Sparkflash Posted October 3, 2014 Share Posted October 3, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/291410-mysql-query-error-not-helpful/ Share on other sites More sharing options...
Barand Posted October 3, 2014 Share Posted October 3, 2014 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` ... Quote Link to comment https://forums.phpfreaks.com/topic/291410-mysql-query-error-not-helpful/#findComment-1492601 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.