Home  >  Article  >  Backend Development  >  注册信息添加到数据库,该怎么处理

注册信息添加到数据库,该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:14:58701browse

注册信息添加到数据库
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]."'这个格式?



------解决方案--------------------

PHP code
$result=mysql_query("select * from STUDENT where S_ID='$user'");if (mysql_num_rows($result)>0){echo "用户名已被使用,请更换";echo "";exit; //加上退出。否则用户名存在也会插入一条数据}$in=mysql_query("insert into STUDENT values('$user','".md5(trim($userword))."','$name','$sex','$tel','$mail')");if(mysql_affected_rows()){echo "恭喜,注册成功";echo "";}else {echo "注册失败";}mysql_close($db);
------解决方案--------------------
运行SQL语句:
SQL code
ALTER TABLE `STUDENT` CHANGE `tel` `tel` VARCHAR(100);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn