JasonO Posted June 23, 2007 Share Posted June 23, 2007 Hi. Is there anything wrong with this syntax? I get an error and it refuses to work :S mysql_query("REPLACE INTO currentcust WHERE id=$cust_id (id, name, email) VALUES ('$cust_id', '$cust_name', '$cust_email') ") or die(mysql_error()); The error: 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 id=34 (id, name, email) VALUES (34,' at line 1 All the variables are right and contain the correct values. Any ideas? Thanks, JasonO Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/ Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 Try this one: mysql_query("REPLACE INTO currentcust WHERE id='$cust_id' (id, name, email) VALUES ('$cust_id', '$cust_name', '$cust_email') ") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280642 Share on other sites More sharing options...
JasonO Posted June 23, 2007 Author Share Posted June 23, 2007 Nope, didn't work. Same error but with '34' instead of 34 Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280644 Share on other sites More sharing options...
eRott Posted June 23, 2007 Share Posted June 23, 2007 I've never heard of any REPLACE function in mySQL. There is however and UPDATE function. Perhaps you are trying to do that? Try this: mysql_query("UPDATE currentcust SET id = '$cust_id', name = '$cust_name', email = '$cust_email' WHERE id=$cust_id") or die(mysql_error()); EDIT: Ok, try this: mysql_query("REPLACE INTO currentcust (id, name, email) VALUES ('$cust_id', '$cust_name', '$cust_email') WHERE id='$cust_id'") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280648 Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 @ eRott Yeh there is replace into function in mysql , Read the manual here. http://dev.mysql.com/doc/refman/4.1/en/replace.html About this query i am not sure about the where clause where it will go in replace into function. Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280651 Share on other sites More sharing options...
JasonO Posted June 23, 2007 Author Share Posted June 23, 2007 I tried eRott's alternative function and that did the trick. Thanks for all your help, and everyone that contributed to helping me Topic solved Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280652 Share on other sites More sharing options...
eRott Posted June 23, 2007 Share Posted June 23, 2007 @mmarif4u Yea, I just googled it. Thanks @JasonO I edited your code. Perhaps placing the WHERE at the end might work? Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280655 Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 Yes in update function where clause will go at very end of the query. Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280656 Share on other sites More sharing options...
eRott Posted June 23, 2007 Share Posted June 23, 2007 I was referring to his REPLACE INTO query . Link to comment https://forums.phpfreaks.com/topic/56805-solved-mysql-replace-error/#findComment-280658 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.