dssk35460 2010-01-18 12:41
浏览 14
已采纳

如何使用php在mysql中搜索记录?

Thanks for all your help, I now have add, update, and delete functions on my database manipulation program. But I'm having difficulty on searching for records in mysql database. Please help me in correcting my codes, and if you know a site that I can use as my reference please do tell. Thanks, here is my search code:

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

      mysql_select_db("koro", $con);

     mysql_query("UPDATE student 
    WHERE IDNUMBER ='$_POST[INAME]'");

    while ($row = mysql_fetch_array($query)) 
    { 
      $variable1=$row["IDNUMBER"]; 
      $variable2=$row["LNAME"]; 
      $variable3=$row["FNAME"]; 
      $variable3=$row["MNAME"]; 
      $variable3=$row["GRADEYR"]; 
      $variable3=$row["ADDRESS"]; 
          } 

       mysql_close($con);

      ?>

And here is the html form that I'm using, and I think this is where the problem is. I don't have any idea on how to put the results in the text box.

  • 写回答

2条回答 默认 最新

  • doujujian0052 2010-01-18 12:48
    关注

    Check the documentation for mysql_query: it returns TRUE or FALSE for UPDATE queries. If you want the new values, follow the UPDATE with a select.

    More importantly, your code is vulnerable to SQL injection. The best solution is to switch from the outdated mysql driver to PDO.

    Unpacking an array into separate variables (as you do) is unnecessary. It's also problematic: notice how you've mistyped the last few names as $variable3.

    Also, don't use "or die" (except in very limited circumstances).

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

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大