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,HowVer ified) 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['Dat e']);
$Name = mysql_real_escape_string($ _POST['Nam e']);
$ScoutingPosition = mysql_real_escape_string($ _POST['Sco utingPosit ion']);
$Team = mysql_real_escape_string($ _POST['Tea m']);
$MyVision = mysql_real_escape_string($ _POST['MyV ision']);
$Smart = mysql_real_escape_string($ _POST['Sma rt']);
$Who = mysql_real_escape_string($ _POST['Who ']);
$What = mysql_real_escape_string($ _POST['Wha t']);
$When = mysql_real_escape_string($ _POST['Whe n']);
$Where = mysql_real_escape_string($ _POST['Whe re']);
$Why = mysql_real_escape_string($ _POST['Why ']);
$How = mysql_real_escape_string($ _POST['How ']);
$HowVerified = mysql_real_escape_string($ _POST['How Verified'] );
$sql="INSERT INTO Ticket (ID,Date,Name,ScoutingPosi tion,Team, MyVision,S mart,Who,W hat,When,W here,Why,H ow,HowVeri fied) VALUES ('$ID','$Date','$Name','$S coutingPos ition','$T eam','$MyV ision','$S mart','$Wh o','$What' ,'$When',' $Where','$ Why','$How ','$HowVer ified')";
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.
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,HowVer
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("*********
$ID = mysql_real_escape_string($
$Date = mysql_real_escape_string($
$Name = mysql_real_escape_string($
$ScoutingPosition = mysql_real_escape_string($
$Team = mysql_real_escape_string($
$MyVision = mysql_real_escape_string($
$Smart = mysql_real_escape_string($
$Who = mysql_real_escape_string($
$What = mysql_real_escape_string($
$When = mysql_real_escape_string($
$Where = mysql_real_escape_string($
$Why = mysql_real_escape_string($
$How = mysql_real_escape_string($
$HowVerified = mysql_real_escape_string($
$sql="INSERT INTO Ticket (ID,Date,Name,ScoutingPosi
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
santoshmotwani,
That makes sense. Date seems to be an exception.
Let me make some changes to the naming and see what happens.
That makes sense. Date seems to be an exception.
Let me make some changes to the naming and see what happens.
ASKER
I clicked on the wrong button!
What wrong button?
ASKER
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
You cant use them