PDA

View Full Version : Error in MySQL Syntax [Help Please]


crazykid
02-09-2010, 10:50 AM
I get the following error message:

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 'Procedure, Rewards, Prereq, Repeatable) VALUES('8', 'test1', '95', 'test1', 'te' at line 1

I'm using the following file to submit information into my database (the code that relates to the error is in bold):

<? include "/home1/sparkonl/public_html/FiestaVault/core_functions.php";
include "checklogin.php";?>
<?
$quest_category = $_POST['Category'];
$quest_name = $_POST['Name'];
$quest_level = $_POST['Level'];
$quest_location = $_POST['Location'];
$quest_npc = $_POST['NPC'];
$quest_objective = $_POST['Objective'];
$quest_procedure = $_POST['Procedure'];
$quest_rewards = $_POST['Rewards'];
$quest_pre = $_POST['Prereq'];
$quest_repeatable = $_POST['Repeatable'];

$error = '0';
//If they are all blank we jsut say to compose a message
if(!$quest_category AND !$quest_name)
{
?>
<p><b><center>Please complete the quest infomation<center></b></p>
<br>
<?
}

//Since this form was partially filled out we need to return an error message
else
{

if (!$quest_name)
{
$error = 'You must enter the quests name';
}

//If the variable error is not set to zero, we have a problem and should show the error message
if($error != '0')
{
echo "<p>$error</p><br>";
}

//There are no errors so far which means the form is completely filled out
else
{
$category_check = $quest_category;
if($category_check > '0')
{



//add quest into the database
mysql_query("INSERT INTO quest (Category, Name, Level, Location, NPC, Objective, Procedure, Rewards, Prereq, Repeatable) VALUES('$quest_category', '$quest_name', '$quest_level', '$quest_location', '$quest_npc', '$quest_objective', '$quest_procedure', '$quest_rewards', '$quest_pre', '$quest_repeatable')") or die (mysql_error());

if ($quest_category = 1) {
$category_name ="quest1-10.php";
}
elseif ($quest_category = 2) {
$category_name ="quest11-20.php";
}
elseif ($quest_category = 3) {
$category_name ="quest21-30.php";
}
elseif ($quest_category = 4) {
$category_name ="quest31-40.php";
}
elseif ($quest_category = 5) {
$category_name ="quest41-50.php";
}
elseif ($quest_category = 6) {
$category_name ="quest51-60.php";
}
elseif ($quest_category = 7) {
$category_name ="quest61-70.php";
}
elseif ($quest_category = 8) {
$category_name ="quest71-80.php";
}
elseif ($quest_category = 9) {
$category_name ="quest81-90.php";
}
elseif ($quest_category = 10) {
$category_name ="quest91-100.php";
}
elseif ($quest_category = 11) {
$category_name ="quest100+.php";
}
elseif ($quest_category = 12) {
$category_name ="questkq.php";
}
else {
echo ERROR;
}

$link_name = str_replace(" ", "_", "$quest_name");
$quest_link = "http://fiestavault.sparkonline.net/quest/$category_name#$link_name";
mysql_query("INSERT INTO master (Name, Link, Namelink) VALUES('$quest_name', '$quest_link', '$link_name')") or die (mysql_error());


//Let the user know everything went ok.
echo "<center><p><b>You have successfully submitted an quest!</b></p></center><br>";
}
//Since they are trying to send messages faster than every 15 seconds, give them an error message
}
//If they mis spelled or, made up a username, then give an error message telling them its wrong.
}

//Since we may have set the error variable to something while trying to send the message, we need another error check
if($error != '0')
{
echo "<p>$error</p><br>";
}

else
{
//Here's the form for the input
?> <center>
<form name="send" method="post" action="submitquest.php">
<table width="100%">
<tr>
<td width="150px" align="center" valign="top"><p><b>Quest Category</b></p> <SELECT NAME="Category">
<OPTION VALUE="">Select a category</OPTION>
<OPTION VALUE=""></OPTION>
<OPTION VALUE="1">Level 1-10</OPTION>
<OPTION VALUE="2">Level 11-20</OPTION>
<OPTION VALUE="3">Level 21-30</OPTION>
<OPTION VALUE="4">Level 31-40</OPTION>
<OPTION VALUE="5">Level 41-50</OPTION>
<OPTION VALUE="6">Level 51-60</OPTION>
<OPTION VALUE="7">Level 61-70</OPTION>
<OPTION VALUE="8">Level 71-80</OPTION>
<OPTION VALUE="9">Level 81-90</OPTION>
<OPTION VALUE="10">Level 90-100</OPTION>
<OPTION VALUE="11">Level 100+</OPTION>
<OPTION VALUE="12">Kingdom Quest</OPTION>
</SELECT></td></tr>
<tr><td>
<center><b>Quest Infomation</b></center>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="50%" align="left" valign="top"><p>Quest Name: <input type="text" name="Name" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting Level: <input type="text" name="Level" value="" size="5" maxlength="5"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Starting Location: <input type="text" name="Location" value="" size="20" maxlength="255"/></p></td>
<td width="50%" align="left" valign="top"><p>Starting NPC: <input type="text" name="NPC" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Objective:<textarea name="Objective" type="text" id="Objective" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Procedure:<textarea name="Procedure" type="text" id="Procedure" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Rewards:<textarea name="Rewards" type="text" id="Rewards" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Pre-Requisites:<input type="text" name="Pre" value="" size="20" maxlength="255"/> </p></td>
</tr>
<tr>
<td width="100%" align="left" valign="top">Repeatable: No<input type="RADIO" name="Repeatable" value="No" checked> Yes<input type="RADIO" name="Repeatable" value="Yes"></td>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit quest"></td>
</tr>
</table>
</center>
</form>
<?
}
?>

Another file I used without any errors looks exactly like the above file. The database names are just different:

<? include "/home1/sparkonl/public_html/FiestaVault/core_functions.php";
include "checklogin.php";?>
<?
$monster_category = $_POST['Category'];
$monster_name = $_POST['Name'];
$monster_picture = $_POST['Picture'];
$monster_type = $_POST['Type'];
$monster_level = $_POST['Level'];
$monster_hp = $_POST['HP'];
$monster_locations = $_POST['Locations'];
$monster_scroll = $_POST['Scrolldrops'];
$monster_potion = $_POST['Potiondrops'];
$monster_stone = $_POST['Stonedrops'];
$monster_quest = $_POST['Questdrops'];
$monster_misc = $_POST['Miscdrops'];
$monster_elite = $_POST['Elite'];
$monster_aggro = $_POST['Aggro'];

$error = '0';
//If they are all blank we jsut say to compose a message
if(!$monster_category AND !$monster_name)
{
?>
<p><b><center>Please complete the monster infomation<center></b></p>
<br>
<?
}

//Since this form was partially filled out we need to return an error message
else
{

if (!$monster_name)
{
$error = 'You must enter the monsters name';
}

//If the variable error is not set to zero, we have a problem and should show the error message
if($error != '0')
{
echo "<p>$error</p><br>";
}

//There are no errors so far which means the form is completely filled out
else
{
$category_check = $monster_category;
if($category_check > '0')
{



//add monster into the database
mysql_query("INSERT INTO monster (Category, Name, Level, Picture, Type, HP, Locations, Scrolldrops, Potiondrops, Stonedrops, Questdrops, Miscdrops, Elite, Aggro) VALUES('$monster_category', '$monster_name', '$monster_level', '$monster_picture', '$monster_type','$monster_hp', '$monster_locations', '$monster_scroll', '$monster_potion', '$monster_stone', '$monster_quest', '$monster_misc', '$monster_elite', '$monster_aggro')") or die (mysql_error());


if ($monster_category = 1) {
$category_name ="monster1-10.php";
}
elseif ($monster_category = 2) {
$category_name ="monster11-20.php";
}
elseif ($monster_category = 3) {
$category_name ="monster21-30.php";
}
elseif ($monster_category = 4) {
$category_name ="monster31-40.php";
}
elseif ($monster_category = 5) {
$category_name ="monster41-50.php";
}
elseif ($monster_category = 6) {
$category_name ="monster51-60.php";
}
elseif ($monster_category = 7) {
$category_name ="monster61-70.php";
}
elseif ($monster_category = 8) {
$category_name ="monster71-80.php";
}
elseif ($monster_category = 9) {
$category_name ="monster81-90.php";
}
elseif ($monster_category = 10) {
$category_name ="monster91-100.php";
}
elseif ($monster_category = 11) {
$category_name ="monster100+.php";
}
elseif ($monster_category = 12) {
$category_name ="monsterkq.php";
}
else {
echo ERROR;
}

$link_name = str_replace(" ", "_", "$monster_name");
$monster_link = "http://fiestavault.sparkonline.net/monster/$category_name#$link_name";
mysql_query("INSERT INTO master (Name, Link, Namelink) VALUES('$monster_name', '$monster_link', '$link_name')") or die (mysql_error());


//Let the user know everything went ok.
echo "<center><p><b>You have successfully submitted an monster!</b></p></center><br>";
}
//Since they are trying to send messages faster than every 15 seconds, give them an error message
}
//If they mis spelled or, made up a username, then give an error message telling them its wrong.
}

//Since we may have set the error variable to something while trying to send the message, we need another error check
if($error != '0')
{
echo "<p>$error</p><br>";
}

else
{
//Here's the form for the input
?> <center>
<form name="send" method="post" action="submitmonster.php">
<table width="100%">
<tr>
<td width="150px" align="center" valign="top"><p><b>Monster Category</b></p> <SELECT NAME="Category">
<OPTION VALUE="">Select a category</OPTION>
<OPTION VALUE=""></OPTION>
<OPTION VALUE="1">Level 1-10</OPTION>
<OPTION VALUE="2">Level 11-20</OPTION>
<OPTION VALUE="3">Level 21-30</OPTION>
<OPTION VALUE="4">Level 31-40</OPTION>
<OPTION VALUE="5">Level 41-50</OPTION>
<OPTION VALUE="6">Level 51-60</OPTION>
<OPTION VALUE="7">Level 61-70</OPTION>
<OPTION VALUE="8">Level 71-80</OPTION>
<OPTION VALUE="9">Level 81-90</OPTION>
<OPTION VALUE="10">Level 90-100</OPTION>
<OPTION VALUE="11">Level 100+</OPTION>
<OPTION VALUE="12">Kingdom Quest</OPTION>
</SELECT></td></tr>
<tr><td>
<center><b>Monster Infomation</b></center>
</td>
</tr>
</table>
<table width="100%">
<tr>
<td width="50%" align="left" valign="top"><p>Monster Name: <input type="text" name="Name" value="" size="20" maxlength="225"/></p></td>
<td width="50%" align="left" valign="top"><p>Monster Type: <input type="text" name="Type" value="" size="15" maxlength="225"/> </p></td>
</tr>
<tr>
<td width="100%" align="left" valign="top"><p>Monster Picture*:<input type="text" name="Picture" value="" size="35" maxlength="225"/></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Monster Level: <input type="text" name="Level" value="" size="2" maxlength="3"/></p></td>
<td width="50%" align="left" valign="top"><p>Monster HP: <input type="text" name="HP" value="" size="3" maxlength="6"/> </p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top">Elite: No<input type="RADIO" name="Elite" value="No" checked> Yes<input type="RADIO" name="Elite" value="Yes"></td>
<td width="50%" align="left" valign="top">Aggro: No<input type="RADIO" name="Aggro" value="No" checked> Yes<input type="RADIO" name="Aggro" value="Yes"></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Common Locations:<textarea name="Locations" type="text" id="Locations" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Scroll Ingredient Drops:<textarea name="Scrolldrops" type="text" id="Scrolldrops" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Potion Ingredient Drops:<textarea name="Potiondrops" type="text" id="Potiondrops" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Stone Ingredient Drops:<textarea name="Stonedrops" type="text" id="Stonedrops" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td width="50%" align="left" valign="top"><p>Possible Quest Drops:<textarea name="Questdrops" type="text" id="Questdrop" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
<td width="50%" align="left" valign="top"><p>Misc Drops:<textarea name="Miscdrops" type="text" id="Miscdrops" value="" cols="30" rows="5" maxlength="500"></textarea></p></td>
</tr>
<tr>
<td><input type="reset" value="Reset" /></td>
<td><input type="submit" name="Submit" value="Submit monster"></td>
</tr>
</table>
</center>
</form>
* For monster Picture please put in the direct link to the picture (if available) E.g. http://sparkonline.net/forums/styles/serenitydarkblue/imageset/sparkonline_logo.gif
<?
}
?>

Here is a screenshot of the database that goes along with the file that works:

http://img18.imageshack.us/img18/5999/fiestamonstersdb.jpg

Here is a screenshot of the database that goes along with the file that returns the error:

http://img18.imageshack.us/img18/7123/fiestaquestsdb.jpg


Does anyone have any ideas as to what might be occurring? Both files are duplicate files, just with different database names for the purpose of inputting data into different databases.

koko5
02-09-2010, 11:01 AM
Hi,
procedure is reserved word (as the same as type: wondering how it works).
These must be escaped by back-quote: `procedure`,`type` etc.
Regards
p.p.: do not use reserved words as column names.

crazykid
02-09-2010, 06:34 PM
Thank you so much! By the way, what is a "reserved word"?

Also, another error came up about Unknown column in 'Category' field name...so I had to create a row called Category in my quest database and made it identical to the Category row (though the collation kept changing itself so I left it alone) that was in the monster database. Worked perfectly after that. :)

koko5
02-09-2010, 07:02 PM
Hi, I'm glad that it helped :)

Here is a list of reserved words (http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-1.html) for mysql version 5.1 or better. Reserved means words with special meaning in ANSI SQL and MySQL in particular.
Sorry, I cannot understand clear:
...error came up about Unknown column in 'Category' field name...but when you've re-created problematical section with required name and you filled it up with metadata, this should be ok : glad that you solved this yourself.

Regards