前台正常:
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<title>邮政编码内容查询范例</title>
</head>
<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
<h1 align="center">邮政编码内容查询</h1>
<form name="form2" action=zip_query.php method=post>
   <p align="center">请输入要查询的县市区域<input type="text" name="zone"></p>
   <p align="center"><input type="submit" name="submit"><input type="reset" name="reset"></p>
</form>
</body>
</html>后台程序总出问题,但我又找不出来,请高手帮我改写一下,谢谢.(都是照书打的)<?php
  $link=mysql_connect("localhost","root","robert");
  mysql_query("use db");
  $sqlstr="select * from zip where zone='".$_POST['zone']."'";
  $result=mysql_query($sqlstr,$link);
  echo "<center>以下是".$_POST['zone']."的邮政编码数据<br>";
  echo "<table border=1>\n";
  echo "<tr>\n";
  while ($field=mysql_fetch_field($result)){
   echo "<td>".$field."</td>\n";}
  echo "</tr>\n";
  while($row=mysql_fetch_row($result)){
    echo "<tr>\n";
    for($i=0;$i<count($row);$i++){
      echo "<td>".$row[$i]."</td>";
    echo "</tr>\n";}
  echo "</table>\n";
      echo "</center>";
  mysql_free_result($result);
  mysql_close($link);
?>数据库中有表zip
id    zip   zone  area
110   555   长春  5654
111   111   长春  5554
112   124   长春  5646我想查询zone字段,然后出现上面的表,后台的程序应该怎么改写呢?

解决方案 »

  1.   

    <?php
      $sqlstr="select * from zip where zone='".$_POST['zone']."'";
      $result=mysql_query($sqlstr,$link);
      while($row=mysql_fetch_array($result)){
      ?>
    <tr>
    <td><? echo $row["id"]?></td>
    <td><? echo $row["zip"]?></td>
    <td><? echo $row["zone"]?></td>
    <td><? echo $row["area"]?></td>
    </tr>
    <?php }?>
      

  2.   

    mysql_query("use db");这一段可能有问题。没有传递链接参数。mysql_query("use db", $link );最好能把错误信息也贴出来看看