Jump to content

php/sql issue


mbrown

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/143291-phpsql-issue/
Share on other sites

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 :D

 

You might consider reading a book on SQL, a lot of people don't know how to use SQL properly.

Link to comment
https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-751505
Share on other sites

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 :D

 

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.

Link to comment
https://forums.phpfreaks.com/topic/143291-phpsql-issue/#findComment-752816
Share on other sites

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.