By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

INSERT into table ? problem

P: 2
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $dbhost    ="";
  3. $dbuser    ="";
  4. $dbpass    ="";
  5. $dbname    ="school";
  6. $db_table = "student"; 
  7.  
  8. $connection=@mysql_connect($dbhost,$dbuser,$dbpass);
  9.     if (!$connection) die ("Mysql connection error" .mysql_error());
  10.     error_reporting(E_ERROR | E_WARNING | E_PARSE);
  11. mysql_select_db($dbname,$connection) or die ("Database connection error");
  12. $query="INSERT INTO $db_table( ID, Name , Surname, Last Name, EGN, Course, Address)
  13. VALUES
  14. ('NULL','{$_POST['Name']}','{$_POST['Surname']}','{$_POST['Last Name']}','{$_POST['EGN']}','{$_POST['Course']}','{$_POST['Address']}')";
  15. if (!mysql_query($query,$connection))
  16.   {
  17.   die('Error: ' . mysql_error());
  18.   }
  19. echo "1 record added";
  20.  
  21. mysql_close($connection);
  22. ?> 

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
Apr 1 '12 #1
Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,349
Name is a reserved key word in SQL, you should rename the column.
Apr 1 '12 #2

Dormilich
Expert Mod 5K+
P: 8,639
and column names should not have spaces either.
Apr 2 '12 #3

P: 2
thanks :))
I corrected it
Apr 2 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.