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

    Join Date
    Jan 2013
    Posts
    15
    Rep Power
    0

    Error Inserting Data into database.


    Hi everyone,
    I am new to PHP and just made a PHP script which inserts data into a table. But i keep getting this error:
    Parse error: syntax error, unexpected 'INSERT' (T_STRING) in C:\xampp\htdocs\PHP\Chapter3\add.php on line 14

    Please help...
    My code is as follows:
    PHP Code:
    <html>
    <head>   
      <title>Make Me Elvis - Add Email</title> 
    </head> 
    <body>
      <?php   
        $fname 
    $_POST['fname'];   
        
    $lname $_POST['lname'];
        
    $email $_POST['email'];
        
    $db mysqli_connect('localhost''root''''elvis_store')
        or die(
    "Error connecting to database');
        
    $query = "INSERT INTO email_list VALUES ('$fname''$lname''$email')";
        
    $result = mysqli_query($db$query)
        or die('Error updating database');
        mysqli_close(
    $db);
        echo 'Customer added';
       ?>
    </body>
    </html>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Sep 2006
    Posts
    1,938
    Rep Power
    533
    Those are tough ones. While it says you have a syntax error on line 14, the error might have originated somewhere before then, and it is just manifesting on line 14. Take an extra look at this line:

    PHP Code:
    or die("Error connecting to database'); 
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,866
    Rep Power
    6351
    Now that your code is colored and highlighted, it's very easy to spot. See how "INSERT" is blue when it should be red. Figure out why.

    You should get an editor which colors/highlights your code for you. EclipsePDT does a good job on Windows/Mac/Linux.
    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.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    15
    Rep Power
    0
    Thanks mate...

IMN logo majestic logo threadwatch logo seochat tools logo