Home > Backend Development > PHP Tutorial > 在注册用户时用两个条件限制

在注册用户时用两个条件限制

WBOY
Release: 2016-06-23 14:11:21
Original
940 people have browsed it

我设计了一个教师注册信息的功能。教师需输入与数据库中对应的姓名和职工号才可注册成功,问题是,如果我只限制与数据库中的姓名相对应便可注册的话,就可以正常注册,如果我限制姓名和职工号两个条件的话,即使我输入正确的姓名和职工号,系统也执行“你输入的信息有误,不属于计算机学院教师”这句。是不是我写的语句有问题?这是我的前台

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /><title>教师注册页面</title><style type="text/css"><!--.STYLE1 {	font-size: 14px;	color: #FF0000;}.STYLE2 {color: #FF0000}.STYLE3 {font-size: 14px}.STYLE4 {font-size: 14px; color: #000000; }.STYLE5 {font-size: 12px}--></style></head><body><?php //######################教师注册##########################  include "conn.php";  include "header.php";?> <p></p><table width="500" border="1" align="center" cellpadding="0" cellspacing="1"  class="text">  <!--DWLayoutTable-->  <form name="form1" method="post" action="teacher_register1.php">    <tr bgcolor="#CDE6C7">       <td height="27" colspan="3"><span class="STYLE1 STYLE2 STYLE1">--->教师注册</span></td>    </tr>	<tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE4">        <div align="right">姓名:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="41"> <input type="text" name="name" size="25">        <span class="STYLE5">*请输入您的真实姓名 </span></td>    </tr>	<tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE4">        <div align="right">职工号:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="41"> <input type="text" name="staffno" size="25">        <span class="STYLE5">*请输入您的职工号 </span></td>    </tr>	<tr>       <td width="148" bgcolor="#CDE6C7"><div align="center" class="STYLE2">        <div align="right" class="STYLE4">密码:</div>      </div></td>      <td width="443" bgcolor="#CDE6C7" height="41"> <input type="password" name="password" size="25">        <span class="STYLE5">*输入密码,长度为3-16位  </span></td>    </tr>	<tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE4">        <div align="right">确认密码:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="41"> <input type="password" name="password1" size="25">      <span class="STYLE3">  </span><span class="STYLE5">*请再次输入密码</span> </td>    </tr>    <tr bgcolor="#CDE6C7">	<td height="25" colspan="2" align="center"><input type="hidden" name="add" value="1">        <input name="submit" type="submit" class="STYLE4"  value="提交">            		 <input type="button" name="back" class="STYLE4" onclick="window.location='index.php'"  value="返回"></td>	</tr>  </form></table><p></p><?php include "foot.php"?> </body></html>
Copy after login

这是我的后台
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /><title>教师注册</title></head><body><?php //######################教师注册##########################  include "conn.php";  include "header.php";  extract($_POST);  if ($name==""||$staffno=""||$password=="" ||$password1=="") {	echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>请把信息添写完整</big></b></font></p>";	echo "<meta http-equiv=\"refresh\" content=\"1;url=teacher_register.php\">";	exit;	}	$query="select * from $teacher_infor where staffno='$staffno'and name='$name'";	mysql_query("set names 'GB2312'");	$result=mysql_query($query);	$row=mysql_fetch_array($result);	if($row==0)	{	 echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你输入的信息有误,不属于计算机学院教师</big></b></font></p>";	 echo "<meta http-equiv=\"refresh\" content=\"2;url=teacher_register.php\">";	 exit;	}	$query="select * from $teacher_table where staffno='$staffno'and name='$name'";	mysql_query("set names 'GB2312'");	$result=mysql_query($query);	$row=mysql_fetch_array($result);	if($row!=0)	{	 echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>此教师已注册,请重新填写</big></b></font></p>";	 echo "<meta http-equiv=\"refresh\" content=\"2;url=teacher_register.php\">";	 exit;	}  if($password!=$password1) {     echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>输入的密码不一致,请重新输入</big></b></font></p>";	 echo "<meta http-equiv=\"refresh\" content=\"2;url=student_register.php\">";	 exit; } $query="insert into $teacher_table values('$staffno','$name','$password')"; mysql_query("set names 'GB2312'"); $result=mysql_query($query); if($result==true){  echo "<p align=\"center\"><font color=\"#FF0000\"><b><big>注册成功!</big></b></font></p>";  echo "<meta http-equiv=\"refresh\" content=\"1;url=jiaoshi_login.php\">";  exit;  }?><?php include "foot.php";?></body></html>
Copy after login


回复讨论(解决方案)

在21行下面 echo $query; 看看是什么结果

在21行下面 echo $query; 看看是什么结果
为什么我输入的职工号是空的,我明明输入了呀

$staffno=""不觉得判断里少点啥?

$staffno=""不觉得判断里少点啥? 啥?

print_r($_POST); 看看

if ($name==""|| $staffno=""||$password=="" ||$password1=="")
怎么只有一个 = ?

if ($name==""|| $staffno=""||$password=="" ||$password1=="")
怎么只有一个 = ? 噢,I'm so sorry!

$staffno=""不觉得判断里少点啥? 不好意思才发现,少了个=,唉

print_r($_POST); 看看 哥,我对不起你,判断语句里少了个= 我的错,唉

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template