wmguk Posted March 12, 2009 Share Posted March 12, 2009 Hi, I've got this script however when I activate it i get an error: include ("connection.php"); include ($_SERVER['DOCUMENT_ROOT'] . "/admin/scripts/audit.php"); $inout = $_POST['inout']; $type = $_POST['type']; $by = $_POST['by']; $user = $_SESSION['username']; $candidate_id = $_POST['candidate_id']; $content = mysql_real_escape_string($_POST['content']); $insertsql = "INSERT INTO candidate_coms (candidate_id, type, inout, by, content, user) VALUES ($candidate_id, $type, $inout, $by, $content, $user)"; mysql_query($insertsql) or die(mysql_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 'inout, by, content, user) VALUES (3693, Phone, in, drew, test, drew)' at line 1 Any ideas what i missed? Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/ Share on other sites More sharing options...
jackpf Posted March 12, 2009 Share Posted March 12, 2009 Try putting` round each of your columns. You may have reserved words as your column names? Just a thought... Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782788 Share on other sites More sharing options...
wmguk Posted March 12, 2009 Author Share Posted March 12, 2009 hmmm, I've changed my columns in the DB to make sure no reserved words are in use, and now have: $insertsql = "INSERT INTO candidate_coms ('com_type','com_by','com_user','com_content','com_inout','candidate_id') VALUES ($type, $by, $user, $content, $inout, $candidate_id)"; mysql_query($insertsql) or die(mysql_error()); getting the same error... Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782799 Share on other sites More sharing options...
wmguk Posted March 12, 2009 Author Share Posted March 12, 2009 ugh, this is wierd, i've changed alsorts now! <?php include ("connection.php"); include ($_SERVER['DOCUMENT_ROOT'] . "/admin/scripts/audit.php"); $coms_user = $_SESSION['username']; $coms_inout = $_POST['coms_inout']; $coms_type = $_POST['coms_type']; $coms_by = $_POST['coms_by']; $candidate_id = $_POST['candidate_id']; $coms_content = mysql_real_escape_string($_POST['coms_content']); $insertsql = "INSERT INTO candidate_coms ('com_type','com_by','com_user','com_content','com_inout','candidate_id') VALUES ($coms_type, $coms_by, $coms_user, $coms_content, $coms_inout, $candidate_id)"; mysql_query($insertsql) or die(mysql_error()); //<META HTTP-EQUIV="Refresh" CONTENT="0; URL=../candidate/viewcandidate.php?candidate_no=<?php echo $candid; "> ?> 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 ''com_type','com_by','com_user','com_content','com_inout','candidate_id') VALUES ' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782801 Share on other sites More sharing options...
wmguk Posted March 12, 2009 Author Share Posted March 12, 2009 when i echo $insertsql i get INSERT INTO candidate_coms ('com_by','com_user','com_content','com_inout','candidate_id') VALUES ('drew', 'drew', 'jvbjcvbjvbj', 'in', '3693') Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782803 Share on other sites More sharing options...
sasa Posted March 12, 2009 Share Posted March 12, 2009 change $insertsql = "INSERT INTO candidate_coms ('com_type','com_by','com_user','com_content','com_inout','candidate_id') VALUES ($coms_type, $coms_by, $coms_user, $coms_content, $coms_inout, $candidate_id)"; mysql_query($insertsql) or die(mysql_error()); to $insertsql = "INSERT INTO candidate_coms (`com_type`,`com_by`,`com_user`,`com_content`,`com_inout`,`candidate_id`) VALUES ('$coms_type', '$coms_by', '$coms_user', '$coms_content', '$coms_inout', '$candidate_id')"; mysql_query($insertsql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782808 Share on other sites More sharing options...
jackpf Posted March 12, 2009 Share Posted March 12, 2009 Yeah, that's probably because you need to put a ` round each column name, not a single quote. Big difference... Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782830 Share on other sites More sharing options...
wmguk Posted March 12, 2009 Author Share Posted March 12, 2009 ugh, what a dumb mistake!!! thanks guys! Quote Link to comment https://forums.phpfreaks.com/topic/149074-solved-you-have-an-error-in-your-sql-syntax/#findComment-782831 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.