Solved

mysql php insert script error

Posted on 2011-02-28
7
382 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
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
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
Comment Utility
0
 

Author Comment

by:dibrandt
Comment Utility
santoshmotwani,

That makes sense. Date seems to be an exception.  
Let me make some changes to the naming and see what happens.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:dibrandt
Comment Utility
I clicked on the wrong button!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
What wrong button?
0
 

Author Comment

by:dibrandt
Comment Utility
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
Comment Utility
You accepted santoshmotwani's comment or had a mod fix it already
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now