mrpatg
mrpatg

Reputation: 10117

Updating MySQL with a where clause

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?

Upvotes: 1

Views: 139

Answers (1)

Eric
Eric

Reputation: 95153

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.

Upvotes: 4

Related Questions