How do you insert in to MYSQL 4.1.22 with PHP 5.2.8?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Websurfer08
    New Member
    • Jun 2010
    • 3

    #1

    How do you insert in to MYSQL 4.1.22 with PHP 5.2.8?

    I am trying to insert data into a MySQL 4.1.22 data base and the code I have used in the past on other servers isn't working. I am currently using PHP 5.2.8. The only way I have been able to make it work, is by using copied code from the PHP MyAdmin section in my cpanel. This copied code, has what appears to be slanted single quotes, but when replaced with regular single quotes it doesn't work. That is the only difference.

    This code works:
    Code:
    $sql="INSERT INTO $table1 (`UID`, `From`, `PostDate`, `FileName`, `FilePath`, `Time`)
    VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
    This code does not work, but should:
    Code:
    $sql="INSERT INTO $table1 (UID, From, PostDate, FileName, FilePath, Time)
    VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
    Please help, I have racked my brain, but cannot figure out why it doesn't work and even though I could copy and past for the rest of my life, I would like to know what is going on.

    Below is the full script that I am using:

    Code:
    $con=mysql_connect("localhost",$user,$PW1);
    if (!$con){
     	die('Could not connect: ' . mysql_error());
     	}mysql_select_db($DB1);
    
    //Input data
    $sql="INSERT INTO $table1 (UID, From, PostDate, FileName, FilePath, Time)
    VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    The only error message I get is that there is an error near 'then it quotes the INSERT INTO section'.

    Thanks!
  • ddsuresh
    New Member
    • Jun 2010
    • 5

    #2
    Code:
    INSERT INTO $table1 (UID, [B]From[/B], PostDate, FileName, FilePath, Time)
    # VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
    "From" sql keyword, if you want to use it as field name then you need to escape it like `From`.

    Comment

    • Websurfer08
      New Member
      • Jun 2010
      • 3

      #3
      Originally posted by ddsuresh
      Code:
      INSERT INTO $table1 (UID, [B]From[/B], PostDate, FileName, FilePath, Time)
      # VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
      "From" sql keyword, if you want to use it as field name then you need to escape it like `From`.
      Awesome! Thank you! Other than copying and pasting, how do I "escape" it?

      Comment

      • ddsuresh
        New Member
        • Jun 2010
        • 5

        #4
        Originally posted by Websurfer08
        Awesome! Thank you! Other than copying and pasting, how do I "escape" it?
        Code:
        INSERT INTO $table1 (UID, `From`, PostDate, FileName, FilePath, Time) VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";
        You have to use the above sql code
        Last edited by Dormilich; Jun 20 '10, 10:02 PM. Reason: Please use [code] tags when posting code

        Comment

        • Websurfer08
          New Member
          • Jun 2010
          • 3

          #5
          Originally posted by ddsuresh
          INSERT INTO $table1 (UID, `From`, PostDate, FileName, FilePath, Time) VALUES ('$UID', '$from', '$postDate', '$DBfileName', '$filePath', NOW())";

          You have to use the above sql code
          I guess what I was wondering was how do I get the single quote to slant? But, I just found it on my keyboard, never new such a key existed!

          Thank you kindly for all the help!

          Comment

          Working...