Jump to content

Mysql query error not helpful...


Sparkflash

Recommended Posts

Can anyone tell me whats wrong with this code?  The mysql error I get is generic and says

 

"Could not enter data: 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 'Tickets (Name,Tech,Node,Address,Tap,Ped,Lash,Hardline,Other,Comments) VALUES ('C' at line 1"

<?php
$name=$_POST['name'];
$id=$_POST['id'];
$node=$_POST['node'];
$ped=$_POST['ped'];
$tap=$_POST['tap'];
$lash=$_POST['lash'];
$hardline=$_POST['hardline'];
$other=$_POST['other'];
$address=$_POST['address'];
$city=$_POST['city'];
$comments=$_POST['comments'];

$dbhost = 'xxxx';
$dbuser = 'xxxx';
$dbpass = 'xxxx';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}


$sql = "INSERT INTO Damage Tickets (Name,Tech,Node,Address,Tap,Ped,Lash,Hardline,Other,Comments) VALUES ('$name','$id','$node','$address','$city','$tap','$ped','$lash','$hardline','$other','$comments')";
mysql_select_db('xxxxx');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not enter data: ' . mysql_error());
}


echo "Your Damage has been Submitted!  <a href=\"damage.php\">Go Back</a>";
mysql_close($conn);

?> 

No idea whats wrong with it?  Thanks for any help

Link to comment
https://forums.phpfreaks.com/topic/291410-mysql-query-error-not-helpful/
Share on other sites

The error message is telling you exactly what is wrong. You cannot have spaces in identifiers (table names, column names etc). If you do you need to enclose them in backticks (note: not single quotes) but it is better to avoid them completely.

INSERT INTO `Damage Tickets` ...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.