<?php
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]."'这个格式?
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]."'这个格式?
{
echo "用户名已被使用,请更换";
break;
}
这个是不是有错?
我在填写注册信息点击注册时,提示超时30秒,陷入死循环了?
把用户提交的用户名带入sql查询。如果查询结果大于0则说明用户名已存在。不让其注册。否则可以注册。
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 * from STUDENT where S_ID='$user'");
if (mysql_num_rows($result)>0)
{
echo "用户名已被使用,请更换";
echo "<script>window.location.href='index.php';</script>";
}
$in=mysql_query("insert into STUDENT values('$user','md5(trim($userword))','$name','$sex','$tel','$mail'");
if($in)
{
echo "恭喜,注册成功";
echo "<script>window.location.href='index.php';</script>";
}
else
{
echo "注册失败";
}
mysql_close($db);
?>
终于没有提出错误了··
可是点击注册后很干脆的跳出注册失败·····
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);
这样试试。
$user=$_POST['user'];
$word=$_POST['psword'];
$userword=md5(trim($word));
$name=$_POST['name'];
$sex=$_POST['sex'];
$tel=$_POST['tel'];
$mail=$_POST['mail'];$result=mysql_query("select * from STUDENT where S_ID='$user'");
if (mysql_num_rows($result)>0)
{
echo "用户名已被使用,请更换";
echo "<script>window.location.href='bishe/index.php';</script>";
exit;
}
$in=mysql_query("insert into STUDENT values('$user','$userword','$name','$sex','$tel','$mail')")or die(mysql_error());
if($in)
{
echo "恭喜,注册成功";
echo "<script>window.location.href='bishe/index.php';</script>";
}
else
{
echo "注册失败";
}
//echo "insert into STUDENT values('$user','md5(trim($userword))','$name','$sex','$tel','$mail')";
mysql_close($db);
?>现在注册信息填入可以,
可是tel里面的数据时错误的,$_tel里面是文本,数据库里面tel是数字类型,这个怎么改?
ALTER TABLE `STUDENT` CHANGE `tel` `tel` VARCHAR(100);
修改原字段名称及类型:mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;