Php / SQL Error

Error in Syntax, but why does it care now?

Page 1 of 1

4 Replies - 552 Views - Last Post: 18 April 2009 - 02:02 PM Rate Topic: -----

#1 Seanmcn  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 15-April 09

Php / SQL Error

Post icon  Posted 18 April 2009 - 08:39 AM

$query = "SELECT * FROM char_stats WHERE id=". $userid;
$result = mysql_query($query) or die(mysql_error());


Getting the error:
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 '' at line 1


Would usually fiddle with this manually, but I dont understand why it can work in one file and then not in another.. :crazy:

This post has been edited by Seanmcn: 18 April 2009 - 11:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Php / SQL Error

#2 BGDeveloper  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 84
  • Joined: 01-April 09

Re: Php / SQL Error

Posted 18 April 2009 - 08:41 AM

Mmmmm
$query = mysql_query("SELECT * FROM `char_stats` WHERE `id` = {$userid}") or die(mysql_error());


try this.
Was This Post Helpful? 1
  • +
  • -

#3 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Php / SQL Error

Posted 18 April 2009 - 08:56 AM

my thots also, reserved name maybe.
but you say works on another page...

may try
if(is_numeric($userid)){
run query....
}

This post has been edited by SpaceMan: 18 April 2009 - 08:56 AM

Was This Post Helpful? 1
  • +
  • -

#4 BMR777  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 36
  • Joined: 01-February 09

Re: Php / SQL Error

Posted 18 April 2009 - 12:26 PM

Maybe:

$query = "SELECT * FROM char_stats WHERE id='$userid'";



OR

$query = "SELECT * FROM char_stats WHERE id='".$userid."'";



Both should work fine. :)
Was This Post Helpful? 0
  • +
  • -

#5 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Php / SQL Error

Posted 18 April 2009 - 02:02 PM

error says at '', so $id was empty, he sent me a note saying it is fixed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1