PHP注册页面不让同名用户重复注册在数据库里。我数据库名user,表名yinfu.字段有用户name,密码有password
我的代码如下 求在线的网友帮我解决更改下代码 就是 用户存在了就不能注册 求求大家帮帮忙啊
<form name="form1" method="POST">
<div align="center"><h2>注册用户</h2></div>
<table border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#0066CC">
<tr><td>用户名:<br>不能超过18个字符(9个汉字)</td>
<td><input type="text" maxlength="18" name="ID"></td>
<tr><td>密码:<br>不能超过12个字符</td>
<td><input type="password" maxlength="12" name="PWD" size="21"></td>
<tr><td>再次密码:</td>
<td><input type="password" maxlength="12" name="PWD_AGAIN" size="21"></td>
<tr><td colspan="3" align="center">
<input type="submit" name="bt1" value="注册">
<input type="reset" name="bt2" value="重写" >
</table>
</form>
<?php
if(isset($_POST['bt1']))
{
$id=$_POST['ID'];
$pwd=$_POST['PWD'];
$pwd_again=$_POST['PWD_AGAIN'];
if($id==""|| $pwd=="")
{
echo"用户名或者密码不能为空";
}
else
{
if($pwd!=$pwd_again)
{
echo"两次输入的密码不一致,请重新输入!";
}
else
{
$conn=mysql_connect("localhost","root","root") or die("数据库连接失败");
mysql_select_db("user");
mysql_query("set names utf8");
$sql="insert into yinfu(name,password)values('{$id}','{$pwd}')";
mysql_query($sql);
$row=mysql_affected_rows($conn);
if($row>0)
{
echo "注册成功!";
echo "<a href='index.php'>登录</a>";
}
else
{
echo"注册不成功!";
}
}
}
}
?>
PHP注册页面不让同名用户重复注册在数据库里。我数据库名user,表名yinfu.字段有用户name,密码有password
å¨è¿ä¹åå个selectæ¥æ¾ççæ没æç¸åçï¼æå°±ä¸åå
¥ï¼æ²¡æå¨åå
¥$sql="insert into yinfu(name,password)values('{$id}','{$pwd}')";
温馨提示:答案为网友推荐,仅供参考
第1个回答 2016-07-07
插入前先判断是否存在这个名字就是啊,