oskare100 Posted November 18, 2006 Share Posted November 18, 2006 Hello,When I run this part of the script[code=php:0]mysql_query("INSERT INTO paypal_sales (viewed_online, viewed_online_by_ip) VALUES('$datenow', '$ip') where $txn_id = $txn_id ") or die(mysql_error());[/code]I get the error [CODE]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 0UU67926P08484626 = 0UU67926P08484626' at line 1[/CODE]If I remove it the script works fine again.. What do you think can be the problem?Best RegardsOskar R Quote Link to comment https://forums.phpfreaks.com/topic/27697-you-have-an-error-in-your-sql-syntax-check/ Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 Hi.In mysql statement for WHERE you cannot add variable=variable. It must be a row name with exuation sign and then some variable. Quote Link to comment https://forums.phpfreaks.com/topic/27697-you-have-an-error-in-your-sql-syntax-check/#findComment-126680 Share on other sites More sharing options...
.josh Posted November 18, 2006 Share Posted November 18, 2006 actually, the problem is that you cannot use a WHERE clause at all in an INSERT query like that. The INSERT query inserts a new row into your table. End of story. If you are trying to add a new row to your table, then take off the where clause and you're done. If you are trying to edit a row, then you need to use UPDATE not INSERT likemysql_query("UPDATE paypal_sales SET viewed_online='$datename', viewed_online_by_ip='$ip' WHERE ....") or die(mysql_error());now normally you would add ... WHERE $txn_id = $txn_id at the end there..but I don't think you've done that right ether. If you were to add that to the end, it would update every single row, because that condition would return true every time because you are comparing a variable to itself. I think what you probably wanted to do was ... WHERE txn_id_column_name_here = $txn_id Quote Link to comment https://forums.phpfreaks.com/topic/27697-you-have-an-error-in-your-sql-syntax-check/#findComment-126716 Share on other sites More sharing options...
Adika Posted November 18, 2006 Share Posted November 18, 2006 Yes. Crayon Violent is right. I didn't see that mistake. :) Quote Link to comment https://forums.phpfreaks.com/topic/27697-you-have-an-error-in-your-sql-syntax-check/#findComment-126725 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.