SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL syntax error

    I'm puzzled because the following works fine:
    PHP Code:
     $info=mysql_query("SELECT works.id, mid, modes_name " .
                       
    "FROM works, modes " .
                       
    "WHERE works.id=$_GET[id] AND works.mid=modes.id ");
      if (!
    $info) {
        echo(
    "Error fetching information: " .
          
    mysql_error());
        exit(); 
    But the following produces an error:
    PHP Code:
     $info=mysql_query("SELECT works.id, works.kid, keys.key_name " .
                       
    "FROM works, keys " .
                       
    "WHERE works.id=$_GET[id] AND works.kid=keys.id ");
      if (!
    $info) {
        echo(
    "Error fetching information: " .
          
    mysql_error());
        exit(); 
    I've checked and rechecked the database structure for the 'modes' and 'keys' tables and they're the same. The 'works' table has both 'mid' and 'kid' fields. The error that the second bit of code produces is:
    Error fetching information: You have an error in your SQL syntax near 'keys WHERE works.id=39 AND works.kid=keys.id ' at line 1
    Does anyone see a problem? Thanks!

  2. #2
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you post the schema ? Also in your second example, why not:

    PHP Code:
    ... WHERE works.id '". $_GET['id'] ."' AND ... 
    Any chance there isn't a PK or simular out of place ?

  3. #3
    SitePoint Zealot toma's Avatar
    Join Date
    Jul 2001
    Location
    Tempe, AZ
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dr Livingston
    Could you post the schema ? Also in your second example, why not:
    PHP Code:
    ... WHERE works.id '". $_GET['id'] ."' AND ... 
    Any chance there isn't a PK or simular out of place ?
    Here is the schema for 'modes'
    #
    # Table structure for table `modes`
    #

    CREATE TABLE modes (
    id int(4) NOT NULL auto_increment,
    modes_name varchar(50) NOT NULL default '',
    modes_definition text NOT NULL,
    modes_comment text NOT NULL,
    heading_top_pic varchar(50) NOT NULL default '',
    modes_heading_pic1 varchar(50) NOT NULL default '',
    modes_heading_pic2 varchar(50) NOT NULL default '',
    modes_heading_pic3 varchar(50) NOT NULL default '',
    modes_top_pic varchar(50) NOT NULL default '',
    modes_pic1 varchar(50) NOT NULL default '',
    modes_pic2 varchar(50) NOT NULL default '',
    modes_pic3 varchar(50) NOT NULL default '',
    PRIMARY KEY (id)
    ) TYPE=MyISAM;
    And for 'keys':
    #
    # Table structure for table `keys`
    #

    CREATE TABLE keys (
    id int(4) NOT NULL auto_increment,
    key_name varchar(50) NOT NULL default '',
    comment text NOT NULL,
    pic text NOT NULL,
    PRIMARY KEY (id)
    ) TYPE=MyISAM;
    I'm not sure what the change to
    PHP Code:
    ... WHERE works.id '". $_GET['id'] ."' AND ... 
    will do? I tried it though with the same outcome.
    What's a PK? Thanks for the reply.
    Last edited by toma; Jun 28, 2003 at 16:42.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •