SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow Script Won't Insert data in Mysql?!

    For some reason, this script won't add data to my mysql table.

    PHP Code:
    //Log Information
    if($global_tracking == "yes"){
        if(
    $LOGGEDIN == "yes"){
            
    $who $UNAME;
        } else {
            
    $who $_SERVER['REMOTE_ADDR'];
        }
        
    $where $_SERVER['PHP_SELF'].'/'.$_SERVER['QUERY_STRING']; //Gets page there on plus anything like "?id=blah"
        
    $when date("M j, Y");
        
    $when $when." at ";
        
    $when $when.date("g:i a");
        
        echo 
    "Who =".$who." and Where = ".$where." and When = ".$when;
        
        
    mysql_query("INSERT INTO log (who, where, when) VALUES('$who', '$where', '$when' ) ") or die(mysql_error());  


    When i put it on a page, it spits out this error:
    Code:
    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, when) VALUES('71.75.243.99', '/angel/index.php/', 'Jul 5

    Anyone know how to fix this? I searched up the error on google, and people get thir error when creating tables, but for some reason, i get it when INSERTING data........ any help?

  2. #2
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    'Where' and 'when' are MySQL reserved words - you shouldn't be using them as column names. You can, however, enclose them in backticks (`where`), but that will ensure that you cannot take this code to any other database.
    PHP questions? RTFM
    MySQL questions? RTFM

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much! I got it working now, and actually, putting the single quotes around the who where and when didn't work, but i changed the name of those in the database to logwho, logwhen, and logwhere so it all works now!

  4. #4
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not single quotes ('when'), backticks (`when`) - on a standard US keyboard it's to the left of the number 1, on the same key as the tilde (~). In SQL, single quotes denote strings ('Hello, world!'), while MySQL (and, to the best of my knowledge, only MySQL) adds the backtick operator to permit the use of reserved words as table and column names (`when`).
    PHP questions? RTFM
    MySQL questions? RTFM


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
  •