4 Replies - 512 Views - Last Post: 07 August 2009 - 09:35 AM Rate Topic: -----

#1 dangmnx  Icon User is offline

  • D.I.C Regular

Reputation: -1
  • View blog
  • Posts: 428
  • Joined: 10-April 09

SQL syntax

Posted 07 August 2009 - 12:00 AM

Quote

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=' at line 3


i don't know why i keep getting this error, what does it mean, and how can i fix it ?
<?php
$connect = mysql_connect("localhost","xrxr","rxrxr") or die (mysql_error());
mysql_select_db("dangmnne_test")or die (mysql_error());

$id = $_POST['id'];
$topic = $_POST['topic'];

$Query = mysql_query("UPDATE forum_question SET
`topic`='$topic',
WHERE id=$id") or die(mysql_error());
header("Location: t_index.php");
?>



Is This A Good Question/Topic? 0
  • +

Replies To: SQL syntax

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 889
  • Joined: 08-August 08

Re: SQL syntax

Posted 07 August 2009 - 12:30 AM

echo out the values of topic and id, that error normally comes when you are trying to enter nothing, also put 'single' around your $id instead of topic. i tend to find that you use single quotes when using a where statement or for matching and none for adding or updating, if someone could clarify that for me too i would be grateful.
Was This Post Helpful? 0
  • +
  • -

#3 sf0145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

Re: SQL syntax

Posted 07 August 2009 - 01:39 AM

Try this:
$Query = mysql_query("UPDATE forum_question SET topic = " . $topic . " WHERE id = " . $id) or die(mysql_error());


This post has been edited by sf0145: 07 August 2009 - 01:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 RPGonzo  Icon User is offline

  • // Note to self: hmphh .... I forgot
  • member icon

Reputation: 151
  • View blog
  • Posts: 954
  • Joined: 16-March 09

Re: SQL syntax

Posted 07 August 2009 - 06:04 AM

sfo was on the track there ... although using double quotes " and not singles ' you dont have to step out of the string for your variables ...

$Query = mysql_query("UPDATE forum_question SET `topic`='$topic' WHERE id='$id'") or die(mysql_error());



any time you have columnname='value' the value must have single quotes around it ... that also includes WHERE statements .... if you step out of the string like sfo did than "technically" you can get away without having them ... i personally prefer to keep it one string though
Was This Post Helpful? 0
  • +
  • -

#5 sf0145  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 03-June 09

Re: SQL syntax

Posted 07 August 2009 - 09:35 AM

I like stepping out of the string for some reason :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1