使用 where 子句更新 MySQL

发布于 2024-08-02 23:55:44 字数 217 浏览 3 评论 0原文

我正在尝试更新 username = $username 的字段

UPDATE userinfo SET password = $newpass WHERE username = $username

但是,当我将 $username 替换为 <代码>鲍勃。

知道如何正确写这个吗?

I'm trying to update a field where username = $username

UPDATE userinfo SET password = $newpass WHERE username = $username

However, I'm getting the error "#1054 - Unknown column 'bob' in 'where clause'" when I replace $username with bob.

Any idea how to correctly write this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳公公是暖光 2024-08-09 23:55:44

啊哈!在您的评论之后,很明显您没有将文本括在引号中:

UPDATE userinfo SET password = $newpass WHERE username = '$username'

由于 $username 是文本值,因此您需要在其周围放置单引号,以便 SQL 将其解析为文本,而不是解析为柱子。

Aha! After your comment, it's clear that you're not wrapping text in quotes:

UPDATE userinfo SET password = $newpass WHERE username = '$username'

Since $username is a text value, you need to put single quotes around it so that SQL parses it as text, not as a column.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文