Jump to content

[SOLVED] MySQL Error


atticus

Recommended Posts

Error:

Error, query failed : 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 com_id = '1'' at line 1

 

$result = mysql_query("UPDATE company SET company_name='$name', address_1 = '$address1', address_2 = '$address2', city ='$city', state ='$state', zip ='$zip', phone ='$phone', WHERE com_id='$_GET[com_id]'") or die('Error, query failed : ' . mysql_error());

 

I can't find the syntax error...any ideas?

Link to comment
Share on other sites

Is com_id an integer or a string? My guess is that it's probably an int. In which case change it to:

 

$result = mysql_query("UPDATE company SET company_name='$name', address_1 = '$address1', address_2 = '$address2', city ='$city', state ='$state', zip ='$zip', phone ='$phone', WHERE com_id=".$_GET['com_id']) or die('Error, query failed : ' . mysql_error());

 

I have changed it above but you need to enclose the get parameter with single quotes:

 

$_GET['com_id']
and not
$_GET[com_id]

 

A word of warning: If you are using $_GET[com_id] straight from the get request make sure you clean it up first to ensure that you are not open to SQL injection.

 

Link to comment
Share on other sites

I added the "." because it is an integer, however now I am getting the following error, same just with "." included

 

Error, query failed : 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 com_id='.1'' at line 1

 

<?php
if(isset($_POST['submit']))

  {
  $id = mysql_escape_string($_POST['com_id']);
      $name = mysql_escape_string($_POST['company_name']);
      $address1 = mysql_escape_string($_POST['address1']);
	$address2 = mysql_escape_string($_POST['address2']);
	$city = mysql_escape_string($_POST['city']);
	$state = mysql_escape_string($_POST['state']); 
	$zip = mysql_escape_string($_POST['zip']);
	$phone = mysql_escape_string($_POST['phone']);
  $result = mysql_query("UPDATE company SET company_name='$name', address_1 = '$address1', address_2 = '$address2', city ='$city', state ='$state', zip ='$zip', phone ='$phone', WHERE com_id='.$_GET[com_id]'") or die('Error, query failed : ' . mysql_error());
          echo "<b>Thank you! User UPDATED Successfully!<br />You will be redirected in 4 seconds";
          echo "<meta http-equiv=Refresh content=4;url=index.php>";
}

Link to comment
Share on other sites

this

 

$result = mysql_query("UPDATE company SET company_name='$name', address_1 = '$address1', address_2 = '$address2', city ='$city', state ='$state', zip ='$zip', phone ='$phone', WHERE com_id='.$_GET[com_id]'") or die('Error, query failed : ' . mysql_error());

 

should be

 

$result = mysql_query("UPDATE company SET company_name='$name', address_1 = '$address1', address_2 = '$address2', city ='$city', state ='$state', zip ='$zip', phone ='$phone' WHERE com_id='.$_GET[com_id]'") or die('Error, query failed : ' . mysql_error());

 

notice I removed the "," before where clause

Link to comment
Share on other sites

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.