Link to home
Start Free TrialLog in
Avatar of dibrandt
dibrandt

asked on

mysql php insert script error

I am a newbe to php and mysql, and I need some help with the script below.

The purpose is to insert html form data, using "POST" into a mysql table. I have compared the column names to the html names, and had another person check them, but I am still getting an error.

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 'When,Where,Why,How,HowVerified) VALUES ('16','','Dixon',' CWBC','Staff','Improve' at line 1

php script:

<?php

$con = mysql_connect("db2836.net","***************","***************");

# mysql_connect("DBSERVER", "DBUSERNAME", "DBPASSWORD");
# mysql_select_db("DBNAME");

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
   
mysql_select_db("***************", $con);

$ID = mysql_real_escape_string($_POST['ID']);
$Date = mysql_real_escape_string($_POST['Date']);
$Name = mysql_real_escape_string($_POST['Name']);
$ScoutingPosition = mysql_real_escape_string($_POST['ScoutingPosition']);
$Team = mysql_real_escape_string($_POST['Team']);
$MyVision = mysql_real_escape_string($_POST['MyVision']);
$Smart = mysql_real_escape_string($_POST['Smart']);
$Who = mysql_real_escape_string($_POST['Who']);
$What = mysql_real_escape_string($_POST['What']);
$When = mysql_real_escape_string($_POST['When']);
$Where = mysql_real_escape_string($_POST['Where']);
$Why = mysql_real_escape_string($_POST['Why']);
$How = mysql_real_escape_string($_POST['How']);
$HowVerified = mysql_real_escape_string($_POST['HowVerified']);

$sql="INSERT INTO Ticket (ID,Date,Name,ScoutingPosition,Team,MyVision,Smart,Who,What,When,Where,Why,How,HowVerified) VALUES ('$ID','$Date','$Name','$ScoutingPosition','$Team','$MyVision','$Smart','$Who','$What','$When','$Where','$Why','$How','$HowVerified')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

echo "The form data was successfully added to your database.";

mysql_close($con);
?>

Any help offered that might move this script to function, would be appreciated.

Avatar of santoshmotwani
santoshmotwani
Flag of Australia image

what i get from this is where & when  & Date are reserved keywords.

You cant use them
ASKER CERTIFIED SOLUTION
Avatar of santoshmotwani
santoshmotwani
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dibrandt
dibrandt

ASKER

santoshmotwani,

That makes sense. Date seems to be an exception.  
Let me make some changes to the naming and see what happens.
I clicked on the wrong button!
Avatar of Michel Plungjan
What wrong button?
The button to accept the solution.  I clicked on the "accept" on my reply, instead of your solution.
You accepted santoshmotwani's comment or had a mod fix it already