注册信息添加到数据库
include("config.php");
$user=$_POST[user];
$userword=$_POST[psword];
$name=$_POST[name];
$sex=$_POST[sex];
$tel=$_POST[tel];
$mail=$_POST[mail];
$result=mysql_query("select S_ID from STUDENT");
while ($row=$result)
{
if($user==$row[S_ID])
{
echo "用户名已被使用,请更换";
break;
}
}
$in=mysql_query("insert into STUDENT value('$user','md5(trim($userword))'),'$name','$sex',$tel,'$mail'");
if($in)
{
echo "恭喜,注册成功";
}
else
{
echo "注册失败";
}
?>
这样可以???
插入语句为什么书上都是直接用'".$_POST[user]."'这个格式?
------解决方案--------------------
$result=mysql_query("select * from STUDENT where S_ID='$user'"); if (mysql_num_rows($result)>0) { echo "用户名已被使用,请更换"; echo "<script>window.location.href='index.php';</script>"; exit; //加上退出。否则用户名存在也会插入一条数据 } $in=mysql_query("insert into STUDENT values('$user','".md5(trim($userword))."','$name','$sex','$tel','$mail')"); if(mysql_affected_rows()) { echo "恭喜,注册成功"; echo "<script>window.location.href='index.php';</script>"; } else { echo "注册失败"; } mysql_close($db); <br><font color="#e78608">------解决方案--------------------</font><br>运行SQL语句:<br>
ALTER TABLE `STUDENT` CHANGE `tel` `tel` VARCHAR(100); <div class="clear"> </div>