Solved

mysql php insert script error

Posted on 2011-02-28
7
387 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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