How do I update MySQL row in PHP?

前端 未结 3 1917
余生分开走
余生分开走 2021-01-24 20:49

I have a MySQL database that I\'m working with, but when I try to update a row in it, it doesn\'t work. Here\'s the update code I\'m working with:

mysql_query(\"         


        
3条回答
  •  春和景丽
    2021-01-24 21:24

    First of all, you should make it a bit more safe:

    mysql_query(sprintf("UPDATE offtopic SET next = '%s' WHERE id = '%s'",
                mysql_real_escape_string($insert),
                mysql_real_escape_string($id));
    

    Now, is your id actually string, and not numeric? If its numeric, you should rather have:

    mysql_query(sprintf("UPDATE offtopic SET next = '%s' WHERE id = %d",
                mysql_real_escape_string($insert), $id);
    

提交回复
热议问题