Solved

mysql php insert script error

Posted on 2011-02-28
7
390 Views
Last Modified: 2012-05-11
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.

0
Comment
Question by:dibrandt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 35003224
what i get from this is where & when  & Date are reserved keywords.

You cant use them
0
 
LVL 16

Accepted Solution

by:
santoshmotwani earned 250 total points
ID: 35003234
0
 

Author Comment

by:dibrandt
ID: 35006377
santoshmotwani,

That makes sense. Date seems to be an exception.  
Let me make some changes to the naming and see what happens.
0
Percona Monitoring and Management and Grafana

Proactive monitoring is vital to a highly-available environment. We have a quick start guide on Experts Exchange for Grafana users.

 

Author Comment

by:dibrandt
ID: 35010441
I clicked on the wrong button!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35011724
What wrong button?
0
 

Author Comment

by:dibrandt
ID: 35012718
The button to accept the solution.  I clicked on the "accept" on my reply, instead of your solution.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35014515
You accepted santoshmotwani's comment or had a mod fix it already
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question