Home > Backend Development > PHP Tutorial > 如何实现输入用户名密码后可查询信息并修改

如何实现输入用户名密码后可查询信息并修改

WBOY
Release: 2016-06-23 14:10:03
Original
992 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></head><body><?php //######################学生信息##########################include "config.php";include "header.php"; ?> <?php extract($_POST); if ($xuehao=="" ||$password=="")  {	echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>请把信息填写完整</big></b></font></p>";	echo "<meta http-equiv=\"refresh\" content=\"1;url=query3.php\">";	exit;	 } else {    $query="select * from $student_table where xuehao='$xuehao'";	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=\"1;url=student_register.php\">";	 exit;	   }			 $query="select password as sm from $student_table where xuehao='$xuehao'";	 mysql_query("set names 'GB2312'");	 $result=mysql_query($query);	 $row=mysql_fetch_array($result);	 $num=strlen($row['xuehao']);	 $xh=$row['xuehao'];	 $n=0;	 if($row[sm]!=$password)	 {		echo"<p align=\"center\"><font color=\"#FF0000\"><b><big>你输入的学号和密码不匹配,请重新输入。</big></b></font></p>";		echo "<meta http-equiv=\"refresh\" content=\"2;url=query3.php\">";		exit;	   }	  	 }?><p></p>		    <table width="600" border="1" align="center" cellpadding="0" cellspacing="1"  class="text">  <!--DWLayoutTable-->  <form name="form1" method="post" action="student_information.php">    <tr bgcolor="#E4E4E4">       <td height="27" colspan="3"><span class="STYLE1">>>>学生信息</span></td>    </tr>    <tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right" class="STYLE4">学号:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="39"> <input type="text" name="xuehao" size="25" value="<?php echo $row['xuehao'] ?>"  readonly="readonly">      </td>    </tr>	<tr>       <td width="148" bgcolor="#E4E4E4"><div align="center" class="STYLE4">        <div align="right">姓名:</div>      </div></td>      <td width="443" bgcolor="#E4E4E4" height="36"> <input type="text" name="name" size="25" value="<?php echo $row['name'] ?>"  readonly="readonly">      </td>    </tr>	<tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right" class="STYLE4">性别:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="41">  <input type="text" name="sex" size="25" value="<?php echo $row['sex'] ?>"  readonly="readonly"></td>    </tr>	<tr>       <td width="148" bgcolor="#E4E4E4"><div align="center" class="STYLE4">        <div align="right">班级:</div>      </div></td>      <td width="443" bgcolor="#E4E4E4" height="36"> <input type="text" name="class" size="25" value="<?php echo $row['class'] ?>"  readonly="readonly">      </td>    </tr>	<tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE2">        <div align="right" class="STYLE4">专业爱好:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="41"><input type="text" name="love" size="25" value="<?php echo $row['love'] ?>"  readonly="readonly">       </td>    </tr>	<tr>       <td width="148" bgcolor="#E4E4E4"><div align="center" class="STYLE2">        <div align="right" class="STYLE4">联系方式:</div>      </div></td>      <td width="443" bgcolor="#E4E4E4" height="41"><input type="text" name="telephone" size="25" value="<?php echo $row['telephone'] ?>"  readonly="readonly">      </td>    </tr>	<tr>       <td width="148" bgcolor="#FFFFFF"><div align="center" class="STYLE4">        <div align="center">本科阶段取得的主要成绩及特长:</div>      </div></td>      <td width="443" bgcolor="#FFFFFF" height="163"><label>        <textarea name="reward" cols="60" rows="10" readonly="readonly"><?php echo $row['reward'] ?></textarea>      </label></td>    </tr>  </form></table><p></p><?php include "foot.php";?></body></html>
Copy after login


回复讨论(解决方案)


$query="select  password as sm from $student_table where xuehao='$xuehao'";
     mysql_query("set names 'GB2312'");
     $result=mysql_query($query);
      $row=mysql_fetch_array($result);
这一段会覆盖前面的$row,而你sql列表中只有sm列,因此下面两行要报错
$num=strlen($row[' xuehao']);
     $xh=$row[' xuehao'];  //没有xuehao 列

下面的各个控件赋值也会报错。

解决办法就是将第二个$row 改为 $row1 

你这个是类似于一个登录界面吧

谢谢,问题解决了,可以正常显示信息了。但是上边那个不必要的错误是什么呢?如图

$query="select  password as sm from $student_table where xuehao='$xuehao'";
     mysql_query("set names 'GB2312'");
     $result=mysql_query($query);
      $row=mysql_fetch_array($result);
这一段会覆盖前面的$row,而你sql列表中只有sm列,因此下面两行要报错
$num=strlen($row[' xuehao']);
     $xh=$row[' xuehao'];  //没有xuehao 列

下面的各个控件赋值也会报错。

解决办法就是将第二个$row 改为 $row1  谢谢!问题解决了,可以正常显示了,但是上面那个错误提示是什么意思?

$row[sm]
改为
$row['sm']

sm不加引号的话,会被当做常量去解析。

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