INSERT into table ? problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Blue Bulgaria
    New Member
    • Apr 2012
    • 2

    INSERT into table ? problem

    Code:
    <?php
    $dbhost	="";
    $dbuser	="";
    $dbpass	="";
    $dbname	="school";
    $db_table = "student"; 
    
    $connection=@mysql_connect($dbhost,$dbuser,$dbpass);
    	if (!$connection) die ("Mysql connection error" .mysql_error());
    	error_reporting(E_ERROR | E_WARNING | E_PARSE);
    mysql_select_db($dbname,$connection) or die ("Database connection error");
    $query="INSERT INTO $db_table( ID, Name , Surname, Last Name, EGN, Course, Address)
    VALUES
    ('NULL','{$_POST['Name']}','{$_POST['Surname']}','{$_POST['Last Name']}','{$_POST['EGN']}','{$_POST['Course']}','{$_POST['Address']}')";
    if (!mysql_query($query,$connection))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($connection);
    ?>

    I don't understand what's the problem

    Error: 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 'Name, EGN, Course, Address) VALUES ('NULL','','',' ','','','')' at line 1
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Name is a reserved key word in SQL, you should rename the column.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      and column names should not have spaces either.

      Comment

      • Blue Bulgaria
        New Member
        • Apr 2012
        • 2

        #4
        thanks :))
        I corrected it

        Comment

        Working...