我的库名db_user 表名tbl_user
字段名有id username password sex。
<?php
$db=mysql_connect("localhost","root","");//连接数据库
mysql_select_db("db_user");
mysql_query("set names utf8");
//判断提交键是否存在
if(isset($_POST['tj'])){
//从表单获取值
$userme=$_POST['username'];
$password=$_POST['password'];
//确认密码
$conpassword=$_POST['conpassword'];
//判断两次密码输入是否一样
if($password==$conpassword){
//向表中插入数据username、password(省略sex)
$sql="insert into tbl_user(username,password) values('$username','$password')";
//执行sql语句
$result=mysql_query($sql);
}
else{
echo "<script>alert('两次密码输入不一致');</script>";
}
if($result)
{
echo "<script>alert('注册成功');</script>";
}
else
{
echo "<script>alert('注册失败);</script>";
}
}
?>
//以下是注册界面,我用的<p></p>你也可以用<div></div>
<form method="post" action="#">
<p>用户名:
<input type="text" name="username" id="username">
</p>
<p>密码:
<input type="password" name="password" id="password">
<div class="item_desc">密码长度6~14位,字母区分大小写。</div>
</p>
<p>确认密码:
<input type="password" name="conpassword" id="conpassword">
</p>
性别:
<input name="sex" type="radio" value="1" checked="checked" />
男
<input type="radio" name="sex" value="2" />
女<br>
<p>
<input type="submit" name="tj" id="tj" value="注册">
<input type="reset" value="重置">
</p>
</form>