douewei1665 2010-01-18 13:33
浏览 23
已采纳

使用php在mysql中列出记录

This is the last thing I'm gonna do, after I can make this work, I can produce to designing which might be a lot easier. Thanks for all your help. I want to list a record from mysql using php by typing a query in the text box. Then the program will list all the records that has that element, for example address. Here is my code:

      <?php
         $con = mysql_connect("localhost","root","");
         if (!$con)
         {
            die('Could not connect: ' . mysql_error());
         }

         mysql_select_db("koro", $con);

         \\what will I put in the WHERE ADDRESS="?
         $result = mysql_query("SELECT * FROM students WHERE ADDRESS=");

         echo "<table border='1'>
               <tr><th>Firstname</th>
               <th>Lastname</th></tr>";

         while($row = mysql_fetch_array($result))
         {
            echo "<tr>";
            echo "<td>" . $row['IDNUMBER'] . "</td>";
            echo "<td>" . $row['LNAME'] . "</td>";
            echo "<td>" . $row['FNAME'] . "</td>";
            echo "<td>" . $row['MNAME'] . "</td>";
            echo "<td>" . $row['GRADEYR'] . "</td>";
            echo "<td>" . $row['ADDRESS'] . "</td>";
            echo "</tr>";
         }
         echo "</table>";

         mysql_close($con);
      ?>

The listform.html:

         <html>
         <head>
         <form action="list.php" method="post">
         address:<input type="text" name="grup" value="" /><br/>
         <input type="submit" name="List" value="" /><br/>
         </form>
         </head>
         </html>

\what will I put in the WHERE ADDRESS="?thanks

  • 写回答

2条回答 默认 最新

  • dourong4031 2010-01-18 13:38
    关注

    You will find the value in the $_POST[] array.

    $result = mysql_query("SELECT * FROM students WHERE ADDRESS = '{$_POST["grup"]}'");
    

    This approach can be dangerous though - you'll want to also sanitize your $_POST[] data against SQL injection attacks - of which there are plenty of tutorials available.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器