CincoPistolero Posted February 21, 2007 Share Posted February 21, 2007 Does anyone see a problem with the below SELECT statement. I am getting the following error: UPDATE contact SET state='MT',main='',firstName='new',lastName='pooh,contactTitle='goo', address='',city='',zip='',contactPhone1='',contactPhone2='', fax='',email1='',email2='',directions='',directionsImageLink='', active='1' WHERE contactID='2' . 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 'goo', address='',city='',zip='',contactPhone1='',contactPhone2 <?php $query = "UPDATE contact SET state='$state',mainPage='$mainPage',firstName='$firstName',lastName='$lastName,contactTitle='$contactTitle', address='$address',city='$city',zip='$zip',contactPhone1='$contactPhone1',contactPhone2='$contactPhone2', fax='$fax',email1='$email1',email2='$email2',directions='$directions',directionsImageLink='$directionsImageLink', active='$active' WHERE contactID='$contactID' "; $result = mysql_query($query) or die ("<div id='main'><center>Error in query: $query. " . mysql_error()."</center></div>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/ Share on other sites More sharing options...
Patrick3002 Posted February 21, 2007 Share Posted February 21, 2007 Does anyone see a problem with the below SELECT statement. I am getting the following error: UPDATE contact SET state='MT',main='',firstName='new',lastName='pooh,contactTitle='goo', address='',city='',zip='',contactPhone1='',contactPhone2='', fax='',email1='',email2='',directions='',directionsImageLink='', active='1' WHERE contactID='2' . 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 'goo', address='',city='',zip='',contactPhone1='',contactPhone2 <?php $query = "UPDATE contact SET state='$state',mainPage='$mainPage',firstName='$firstName',lastName='$lastName,contactTitle='$contactTitle', address='$address',city='$city',zip='$zip',contactPhone1='$contactPhone1',contactPhone2='$contactPhone2', fax='$fax',email1='$email1',email2='$email2',directions='$directions',directionsImageLink='$directionsImageLink', active='$active' WHERE contactID='$contactID' "; $result = mysql_query($query) or die ("<div id='main'><center>Error in query: $query. " . mysql_error()."</center></div>"); ?> Try using mysql_real_escape_string on all of the vars in the UPDATE query. Put this code before the $query $state = mysql_real_escape_string($state); $mainPage = mysql_real_escape_string($mainPage); $firstName = mysql_real_escape_string($firstName); $lastName = mysql_real_escape_string($lastName); $contactTitle = mysql_real_escape_string($contactTitle); $address = mysql_real_escape_string($address); $city = mysql_real_escape_string($city); $zip = mysql_real_escape_string($zip); $contactPhone1 = mysql_real_escape_string($contactPhone1); $contactPhone2 = mysql_real_escape_string($contactPhone2); $email1 = mysql_real_escape_string($email1); $email2 = mysql_real_escape_string($email2); $directions = mysql_real_escape_string($directions); $directionsImageLink = mysql_real_escape_string($directionsImageLink); $active = mysql_real_escape_string($active); $contactID = mysql_real_escape_string($contactID); Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/#findComment-190316 Share on other sites More sharing options...
CincoPistolero Posted February 21, 2007 Author Share Posted February 21, 2007 I still get the same error. I use this same code on other modify pages, and it works fine. Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/#findComment-190317 Share on other sites More sharing options...
Patrick3002 Posted February 21, 2007 Share Posted February 21, 2007 Try using this query: <?php $query = "UPDATE `contact` SET state=\"$state\", mainPage=\"$mainPage\", firstName=\"$firstName\", lastName=\"$lastName\", contactTitle=\"$contactTitle\", address=\"$address\", city=\"$city\", zip=\"$zip\", contactPhone1=\"$contactPhone1\", contactPhone2=\"$contactPhone2\", fax=\"$fax\", email1=\"$email1\", email2=\"$email2\", directions=\"$directions\", directionsImageLink=\"$directionsImageLink\", active=\"$active\" WHERE contactID='$contactID' "; $result = mysql_query($query) or die ("<div id='main'><center>Error in query: $query. " . mysql_error()."</center></div>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/#findComment-190318 Share on other sites More sharing options...
Patrick3002 Posted February 21, 2007 Share Posted February 21, 2007 If that doesn't work then this will deffinatly work with the mysql_real_escape_string script i gave you earlier. <?php $query = "UPDATE contact SET state='$state',mainPage='$mainPage',firstName='$firstName',lastName='$lastName',contactTitle='$contactTitle', address='$address',city='$city',zip='$zip',contactPhone1='$contactPhone1',contactPhone2='$contactPhone2', fax='$fax',email1='$email1',email2='$email2',directions='$directions',directionsImageLink='$directionsImageLink', active='$active' WHERE contactID='$contactID' "; $result = mysql_query($query) or die ("<div id='main'><center>Error in query: $query. " . mysql_error()."</center></div>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/#findComment-190320 Share on other sites More sharing options...
monk.e.boy Posted February 21, 2007 Share Posted February 21, 2007 UPDATE contact SET state='MT',main='',firstName='new',lastName='pooh,contactTitle='goo', address='',city='',zip='',contactPhone1='',contactPhone2=''...... you are missing a quote after pooh monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/#findComment-190345 Share on other sites More sharing options...
CincoPistolero Posted February 27, 2007 Author Share Posted February 27, 2007 that fixed it Quote Link to comment https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/#findComment-195008 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.