PHP variable in UPDATE query

I am trying to pass a variable in an SQL UPDATE statement but it doesn’t seem to work and I can’t see where I am going wrong. Can anyone advise?

mysql_query("UPDATE Notes SET DateDue = '2014-10-11', Title='".$title."' WHERE NoteId = '1'");

Thanks in advance

Aaargh! Found the problem, it was a scope problem. I was passing the correct variables and echoing them showed the values were fine, but the update statement was outwith the scope. Working like a treat now :slight_smile:

It’s good to see that you’ve found your error. Though I would highly advise (and encourage) you to avoid using the original MySQL extension. Have a read of the sticky at the top of this section as to why it would be in your best interest to switch over to a newer API.

Once you’ve migrated over to either the mysqli_* extension or more preferably PDO you should be using prepared statements when dealing with user submitted data that’s being used in a query, once the user submitted data has been validated