如何在PHP中更新MySQL行? [英] How do I update MySQL row in PHP?

查看:110
本文介绍了如何在PHP中更新MySQL行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在使用的MySQL数据库,但是当我尝试更新其中的一行时,它不起作用.这是我正在使用的更新代码:

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("UPDATE offtopic SET next = '$insert' WHERE id = '$id'");

推荐答案

首先,您应该使其更加安全:

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));

现在,您的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);

这篇关于如何在PHP中更新MySQL行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆