duanfei1930 2014-07-29 21:12
浏览 13

MySQL不会更新

This is my first time on SO, so I'm not knowing about everything. I'm sorry. I have a problem with my site. I want to update the viewed status of one of the rows.

This is my update code:

<?php
   if(isset($_POST['Submit'])){//if the submit button is clicked

      $sql= mysql_query ("UPDATE system_reports SET viewed=1 WHERE id =' ".$row['id']." ' ");
      $conn->query($sql) or die("Cannot update");//update or error
   }
?>

But when I click on the button, I get: Cannot Update. The connection of DB is fine. So I don't know what is the problem. ID is a realy working variable.

So is my rows working:

<?php
   function spam_Draw() {
      $a = mysql_query("SELECT * FROM system_reports WHERE viewed=0");
      while ($row = mysql_fetch_array($a)) {    
         echo $row['id']." <a href='http://warrock-hack.net/profiel/".$row['user'] . "/'>Gedupeerde</a> <a href='" . $row['report_url'] . "'> Ga naar het probleem toe!</a>    " . $row['reason'];
         echo '<br>';
         echo '<INPUT TYPE="Submit" VALUE="Update the Record" NAME="Submit"> ';
      }
   }
?>

I hope someone can help me out! Thanks..

Regards,

John.

  • 写回答

1条回答 默认 最新

  • doujiao2443 2014-07-29 21:15
    关注

    Your DB calls are totally wrong. mysql_query() returns a query handle representing the results of your query (or boolean false on failure). You're taking that handle, and feeding it to some OTHER database library.

    mysql, mysqli and PDO database handles/results are NOT interchangeable, and the libraries cannot be mixed together like that.

    You probably want something more like:

    $sql = "UPDATE....  " . $row['id'];  // no mysql_query() call, just defining a string
    $result = $conn->query($sql);
    

    Plus, die()ing with a fixed string for your error message is utterly useless. The DB libraries can TELL you what the problem was:

    $result = $conn->query($sql) or die(mysqli_error()); // assuming mysqli
    
    评论

报告相同问题?

悬赏问题

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