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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.