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 Quote Link to comment 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()); Quote Link to comment 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 Quote Link to comment 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()); Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 . Quote Link to comment 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.