Canman2005 Posted May 19, 2007 Share Posted May 19, 2007 Hi all I am trying to run the following query IF EXISTS(SELECT * FROM `md` WHERE `rn` = 'DD') UPDATE `md` SET `rn`='CC' ELSE INSERT `md` SET `rn`='BB'; But I get a #1064 - You have an error in your SQL syntax; Does anyone know why? Thanks Dave Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 Thats not a valid SQL statement.. infact what are you traying to do ? Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted May 19, 2007 Author Share Posted May 19, 2007 im trying to see if a record exists and if it does to update the information and if it doesnt exist then it would insert the data Quote Link to comment Share on other sites More sharing options...
MadTechie Posted May 19, 2007 Share Posted May 19, 2007 your need to do the select then check mysql_num_rows($result); for the number of records found then if more than one apply update.. i think some research may help Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted May 19, 2007 Share Posted May 19, 2007 <?php $sql = mysql_query("SELECT * FROM `md` WHERE `rn` = 'DD'"); $count = mysql_num_rows($sql); if ($count > 0){ //record exists mysql_query("UPDATE `md` SET `rn`='CC'"); } else { //record doesn't exist //INSERT QUERY HERE } ?> Your INSERT query doesn't make any sense...so you might want to do a google on that. 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.