Jump to content

Recommended Posts

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>");
?>

Link to comment
https://forums.phpfreaks.com/topic/39440-solved-error-in-select-query/
Share on other sites

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);

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>");
?>

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>");
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.