Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mysql php insert script error

Posted on 2011-02-28
7
Medium Priority
?
393 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 1000 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
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

670 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