Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Location
    wwwroot
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up INSERT INTO Statement error....???[Resolved}

    Hello All,


    I have part of a PHP page I am trying to write which i want it to write information to a database. I have the odbc system dsn created on my machine. And I was able to execute a simple "Select * From" Clause using the same source, but this sql statement i have in the code below is giving me all sorts of trouble:


    PHP Code:
    <html>
    <body>


    <?php

    $userIP
    =$_SERVER["REMOTE_ADDR"];
    $DateStr=date("l dS of F Y h:i:s A");
    $FlashVer="Flash V6";
    $BrowseVer=$_SERVER["HTTP_USER_AGENT"];


    $conn=odbc_connect('FlashStats','',''); 
    if (!
    $conn)
    {
    exit(
    "Connection Failed: " $conn); 

    $sql="INSERT INTO [Jun 2005] (IPAddress, DateTime, Flashversion, Browserversion) " .
    "VALUES ('$userIP', '$DateStr', '$FlashVer', '$BrowseVer') ";
    echo 
    $sql;
    $rs=odbc_exec($conn,$sql); 
    if (!
    $rs)

    exit(
    "Error in SQL");


    ?>


    </body>
    </html>
    And here is the output in the browser:

    INSERT INTO [Jun 2005] (IPAddress, DateTime, Flashversion, Browserversion) VALUES ('127.0.0.1', 'Tuesday 21st of June 2005 09:57:46 AM', 'Flash V6', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)')
    Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement., SQL state 37000 in SQLExecDirect in c:\phpdev\www\test\odbc.php on line 21
    Error in SQL
    Does anyone know what the hell this means and how to fix it?!?!?

    Thanks in advance,

    Xman51
    Last edited by xman51; Jun 21st, 2005 at 07:00 PM. Reason: [Resolved}
    Xman51
    Area 51

  2. #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,280
    Thanks
    6
    Thanked 49 Times in 49 Posts
    PHP Code:
    $sql="INSERT INTO 'Jun 2005' (IPAddress, DateTime, Flashversion, Browserversion) " .
    "VALUES ('$userIP', '$DateStr', '$FlashVer', '$BrowseVer')"

  3. #3
    New to the CF scene
    Join Date
    Jun 2005
    Location
    wwwroot
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down

    Thanks for the quick reply...now it gives me this error:

    INSERT INTO 'Jun 2005' (IPAddress, DateTime, Flashversion, Browserversion) VALUES ('127.0.0.1', 'Tuesday 21st of June 2005 10:16:50 AM', 'Flash V6', 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)')
    Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in query. Incomplete query clause., SQL state S1000 in SQLExecDirect in c:\phpdev\www\test\odbc.php on line 21
    Error in SQL
    See where it says Incomplete query clause?

    Thanks again,

    Xman51
    Xman51
    Area 51

  4. #4
    New to the CF scene
    Join Date
    Jun 2005
    Location
    wwwroot
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Here is the solution for all who is interested:

    PHP Code:
    $sql="INSERT INTO Jun2005 " 
    "VALUES ('$userIP', '$DateStr', '$FlashVer', '$BrowseVer', '$referer', '$Entry', '$Exit', '$Hits', '$Files', '$Pages', '$Kbytes')"
    Make sure you dont have a primary key selected in the db, and that your formats are correct. (The reason it wouldn't write to the database is because the date format did not match...tee hee ) Also in this format you have to give a value for every field in the db. If any of them have been omitted then it will throw an error.

    Thanks to all for your assistance,

    Xman51
    Xman51
    Area 51


 

Posting Permissions

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