mbrown Posted January 31, 2009 Share Posted January 31, 2009 l get the following 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 'Grant, Building, Room, Status, Specs, WorkedOn) VALUES('123457', '555555555', 'H' at line 1 INSERT INTO equipment (DistrictTag, SerialNumber, Type, Type1, Model, DateofPurchase, Grant, Building, Room, Status, Specs, WorkedOn) VALUES('123457', '555555555', 'HP 1510 LCD Monitor', '', 'HP', '', 'None', 'WASHS', '204', 'In Use', 'None', ''); This is the query $query = "INSERT INTO equipment (DistrictTag, SerialNumber, Type, Type1, Model, DateofPurchase, Grant, Building, Room, Status, Specs, WorkedOn) VALUES('$districtId', '$serialId', '$type', '$type1', '$model', '$dateofPurcahse', '$grant', '$building', '$room', '$status', '$specs', '$workedOn');"; echo "<br /><br />"; mysql_query($query, $db) or die(mysql_error($db) . '<br />' . $query); what do i have wrong? Quote Link to comment https://forums.phpfreaks.com/topic/143291-phpsql-issue/ Share on other sites More sharing options...
Guardian-Mage Posted January 31, 2009 Share Posted January 31, 2009 I believe one of your column names is a reserved syntax word. To avoid this, surround the column names with a backtick, `, and values with a single quote, '. <?php $query = "INSERT INTO `equipment` (`DistrictTag`, `SerialNumber`, `Type`, `Type1`, `Model`, `DateofPurchase`, `Grant`, `Building`, `Room`, `Status`, `Specs`, `WorkedOn`) VALUES('$districtId', '$serialId', '$type', '$type1', '$model', '$dateofPurcahse', '$grant', '$building', '$room', '$status', '$specs', '$workedOn');"; echo "<br /><br />"; mysql_query($query, $db) or die(mysql_error($db) . '<br />' . $query); ?> Oh, and Google would have given you the answers to your question You might consider reading a book on SQL, a lot of people don't know how to use SQL properly. Quote Link to comment https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-751505 Share on other sites More sharing options...
pocobueno1388 Posted January 31, 2009 Share Posted January 31, 2009 If what Guardian-Mage suggested doesn't fix it, try to use mysql_real_escape_string() on all your variables. Quote Link to comment https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-751506 Share on other sites More sharing options...
Guardian-Mage Posted January 31, 2009 Share Posted January 31, 2009 That wouldn't fix the problem because of where the error is occuring. It is not occuring in the data field section, but in the column name section. -Guardian Mage Quote Link to comment https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-751508 Share on other sites More sharing options...
mbrown Posted January 31, 2009 Author Share Posted January 31, 2009 Thank you all for your help. I have fixed my issue. What I did is I went into my phpmyadmin and inserted a record and see how things were there. Quote Link to comment https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-751527 Share on other sites More sharing options...
mbrown Posted February 2, 2009 Author Share Posted February 2, 2009 I believe one of your column names is a reserved syntax word. To avoid this, surround the column names with a backtick, `, and values with a single quote, '. <?php $query = "INSERT INTO `equipment` (`DistrictTag`, `SerialNumber`, `Type`, `Type1`, `Model`, `DateofPurchase`, `Grant`, `Building`, `Room`, `Status`, `Specs`, `WorkedOn`) VALUES('$districtId', '$serialId', '$type', '$type1', '$model', '$dateofPurcahse', '$grant', '$building', '$room', '$status', '$specs', '$workedOn');"; echo "<br /><br />"; mysql_query($query, $db) or die(mysql_error($db) . '<br />' . $query); ?> Oh, and Google would have given you the answers to your question You might consider reading a book on SQL, a lot of people don't know how to use SQL properly. You were correct "Type" & "Grant" were two. I ran it through PHPMYADMIn to see which ones were. Quote Link to comment https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-752816 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.