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

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.