0

Hi,

Can someone tell me if i can use the below query.

When i click submit button SQL says:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE username = 'genieuk'' at line 1

I am using this query:

$loginid = mysql_query("INSERT INTO userinformation (login_id) VALUES ('".$randomkey."') WHERE `username` = '".$username."'") or die(mysql_error());

Thanks
Mat

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by genieuk
0

I think that if you are using a WHERE clause to find an existing row in a table to change a value, you should be using UPDATE instead of INSERT INTO. (You also have to use the syntax "SET column=value"

Something like:

$loginid = mysql_query("UPDATE userinformation SET login_id='".$randomkey."' WHERE `username` = '".$username."'") or die(mysql_error());

Double-check this in the MySQL manual for your version of MySQL, since I am hardly an expert.

0

I think that if you are using a WHERE clause to find an existing row in a table to change a value, you should be using UPDATE instead of INSERT INTO. (You also have to use the syntax "SET column=value"

Something like:

$loginid = mysql_query("UPDATE userinformation SET login_id='".$randomkey."' WHERE `username` = '".$username."'") or die(mysql_error());

Double-check this in the MySQL manual for your version of MySQL, since I am hardly an expert.

Hello,

Thanks for the the information. It worked great :)

Thanks,
Mat

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.