#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2008
    Location
    NY
    Posts
    17
    Rep Power
    0

    SQL Syntax Error...?


    Hi y'all.

    I'm trying to insert data into a mySQL table in PHP, but I've been getting this error all afternoon, and can't seem to move past it:

    Code:
    Could not connects: 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, creator, email) VALUES ('HikeAtPruyne', 10, 7, 2012, '11:15', 'Hike At Pr' at line 1
    Here's my code:

    PHP Code:
    if(mysql_query("INSERT INTO events (metaname, month, day, year, time, propname, description, where, creator, email) VALUES ('$metaname', $month$day$year, '$time', '$name', '$description', '$where', '$_SESSION[myusername]', '$email')"))
                        { echo 
    "Event succesfuly created!";} else{ die('Could not connects: ' mysql_error()); }
                        
    mysql_close($con); 
    Anyone have any ideas?
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,128
    Rep Power
    1990
    The answer is actually very simple.

    WHERE is a reserved word in SQL, so you really should not be using that for a table or column name.

    However, you can get around that by adding back-ticks to your column name so that MySQL knows that it's not the language construct. As a personal thing I an also very wary about using words like date, time, etc because these can also have some meaning for MySQL functions.

    Code:
    INSERT INTO events (`metaname`, `month`, `day`, `year`, `time`, `propname`, `description`, `where`, `creator`, `email`)

    Comments on this post

    • ManiacDan agrees
  4. #3
  5. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    4
    Rep Power
    0
    where is an reserved word in SQL, so you can't use it as a variable declaration.

    Comments on this post

    • Catacaustic disagrees : That's what I said.. but I showed how you can. Please read what's been posted before you add the same thing again.
    Last edited by ManiacDan; October 5th, 2012 at 09:16 AM.
  6. #4
  7. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,552
    Rep Power
    2337
    Catacaustic, it's just another Indian SEO spammer.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Another SEO spammer who has been banned and pruned.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2008
    Location
    NY
    Posts
    17
    Rep Power
    0
    Thanks guys, that did it. I changed the where variable to location and that solved the problem. <3 you guys.

IMN logo majestic logo threadwatch logo seochat tools logo