forumnz Posted December 29, 2007 Share Posted December 29, 2007 Hello, I get this error when executing the below code: 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 'desc, keyw, addst, addsu, addci, addre, addpc, userid, ph, ph2, freeph, fax, ema' at line 1 <?php $buzzname=$_POST['buzzname']; $sub=$_POST['sub']; $desc=$_POST['desc']; $keyw=$_POST['keyw']; $addst=$_POST['addst']; $addsu=$_POST['addsu']; $addci=$_POST['addci']; $addre=$_POST['addre']; $addpc=$_POST['addpc']; $ph=$_POST['ph']; $ph2=$_POST['ph2']; $freeph=$_POST['freeph']; $fax=$_POST['fax']; $email=$_POST['email']; $uid = $_SESSION['id']; include('../dbcon.php'); $sql="INSERT INTO cmads (buzzname, sub, desc, keyw, addst, addsu, addci, addre, addpc, userid, ph, ph2, freeph, fax, email) VALUES ('$buzzname','$sub','$desc','$keyw','$addst','$addsu','$addci','$addre','$addpc','$uid','$ph','$ph2','$freeph','$fax','$email')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; ?> Whats going on? I have a similar page which works: <?php $fname=$_POST['fname']; $lname=$_POST['lname']; $buzzname=$_POST['buzzname']; $buzzaddst=$_POST['buzzaddst']; $buzzaddsu=$_POST['buzzaddsu']; $buzzaddci=$_POST['buzzaddci']; $buzzaddre=$_POST['buzzaddre']; $buzzpc=$_POST['buzzpc']; $buzzph=$_POST['buzzph']; $buzzph2=$_POST['buzzph2']; $buzzfreeph=$_POST['buzzfreeph']; $buzzfax=$_POST['buzzfax']; $uaddst=$_POST['uaddst']; $uaddsu=$_POST['uaddsu']; $uaddci=$_POST['uaddci']; $upc=$_POST['upc']; $uph=$_POST['uph']; $uph2=$_POST['uph2']; $ufax=$_POST['ufax']; $email=$_POST['email']; $username=$_POST['username']; $password=$_POST['password']; $password = md5($password); include('../dbcon.php'); $sql="INSERT INTO cmusers (ufname, ulname, buzzname, buzzaddst, buzzaddsu, buzzaddci, buzzaddre, buzzpc, buzzph, buzzph2, buzzfreeph, buzzfax, uaddst, uaddsu, uaddci, upc, uph, uph2, ufax, email, username, password) VALUES ('$fname','$lname','$buzzname','$buzzaddst','$buzzaddsu','$buzzaddci','$buzzaddre','$buzzpc','$buzzph','$buzzph2','$buzzfreeph','$buzzfax','$uaddst','$uaddsu','$uaddci','$ups','$uph','$uph2','$ufax','$email','$username','$password')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } echo "1 record added"; ?> Thanks, Sam. Link to comment https://forums.phpfreaks.com/topic/83632-solved-insert-error/ Share on other sites More sharing options...
AndyB Posted December 29, 2007 Share Posted December 29, 2007 desc is a reserved word. Avoid using reserved words as table or field names. Sloppy workaround is to enclose the name with `backticks` Link to comment https://forums.phpfreaks.com/topic/83632-solved-insert-error/#findComment-425441 Share on other sites More sharing options...
MadTechie Posted December 29, 2007 Share Posted December 29, 2007 i think desc is reserved EDIT: to slow! Link to comment https://forums.phpfreaks.com/topic/83632-solved-insert-error/#findComment-425444 Share on other sites More sharing options...
AndyB Posted December 29, 2007 Share Posted December 29, 2007 i think desc is reserved I know it is http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Link to comment https://forums.phpfreaks.com/topic/83632-solved-insert-error/#findComment-425445 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.