$username=$_POST['username']; //已经注册了的名字 $password=$_POST['password']; $username1=$_POST['username1']; //注册的名字 //接受输入的内容 include("db.php");
if($username1==''||$password==''){
echo "用户名和密码不能为空!请重新输入!"; echo "<a href=index.php>[注册]</a>"; exit;
}
$sql="select * from admin where username='$username'"; $rs=mysql_query($sql,$conn);
$arr = mysql_fetch_array($rs,MYSQL_ASSOC); if($arr['username']==$username1){
echo "用户名已存在,请重新注册!";
echo "<a href=index.php>[注册]</a>";
}else{
mysql_query("insert into admin(username,password) values ('$username1','$password')",$conn);
echo $username1.",您好注册成功,请您登录!<a href=manage.php>[登录]</a>";
}
第一种:就是相同用户只能注册一次,这个加个主键就可以了,也可以通过查询数据库是不是存在这个用户,如果存在,提示该用户已经注册,这个最好的办法是采用Ajax在注册页面直接判断。
第二种:就是一个人职能注册一个帐号,这个就有记录IP地址了,
<?php
$username = $_POST['username']; //已经注册了的名字 $password=$_POST['password'];
$username1=$_POST['username1']; //注册的名字
//接受输入的内容 include("db.php");
if ($username1 == '' || $password == '')
{
echo "用户名和密码不能为空!请重新输入!";
echo "<a href=index.php>[注册]</a>";
exit;
}
$sql = "select * from admin where username='$username1'";
$rs = mysql_query($sql, $conn);
if(mysql_num_rows($rs)>0)
{
echo "用户名已存在,请重新注册!";
echo "<a href=index.php>[注册]</a>";
} else
{
mysql_query("insert into admin(username,password) values ('$username1','$password')",
$conn);
echo $username1 . ",您好注册成功,请您登录!<a href=manage.php>[登录]</a>";
}
?>本回答被网友采纳