Search code examples
mysqlsqlmysql-error-1054

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?


Solution

  • 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.