这是我的代码,运行结果如图。如何显示出数据库信息并可以修改某一项。<!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">&gt;&gt;&gt;学生信息</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>

解决方案 »

  1.   

    $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 
      

  2.   

    $row[sm]
    改为
    $row['sm']sm不加引号的话,会被当做常量去解析。