duanqianhuan3994 2012-11-27 02:14
浏览 36
已采纳

MySQL表行不会UPDATE

I am trying to update a column in a row in a MySQL table. The column is the 'votes' column and when someone submits an HTML form there is a hidden input with a value of "1" that gets submit and posted. This is the code I am using to try to update the vote count:

if(isset($_POST['image_id']) && isset($_POST['vote'])){
    $image_id = $mysqli->real_escape_string($_POST['image_id']);
    $vote = $mysqli->real_escape_string($_POST['vote']);

    $sql_users_vote = "SELECT * FROM users WHERE id='$image_id'";
    $result_users_vote = $mysqli->query($sql_users_vote);
    $row_vote = mysqli_fetch_array($result_users_vote);
    $votes_count = $row_vote['votes'];
    $new_votes = $votes_count + $vote;

    $sql_vote = "UPDATE users WHERE id='$image_id' SET votes=$new_votes";
   $result_vote = $mysqli->query($sql_vote);
 }

I have echo'ed out the variable up until $sql_vote and $image_id, $vote, $votes_count and $new_votes all echo out the correct values. I'm guessing that there is a problem in the UPDATE syntax. I've checked it over and over but can't seem to find anything. I know that I don't have quotes around $new_votes in the UPDATE because I believe that is correct syntax. I've tried it with quotes and it doesn't work that way either.

Can someone help me identify the problem? Thanks!

  • 写回答

2条回答 默认 最新

  • dongliang1865 2012-11-27 02:18
    关注
    $sql_vote = "UPDATE users SET votes=$new_votes WHERE id='$image_id'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)