rojocapo Posted January 4, 2009 Share Posted January 4, 2009 I'm currently working on an admin panel, and when I try adding an item to the database I get this 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 'ItemCategory = 'Array', ItemText = '|sfdgsdfgsd', ItemImage = '', ' at line 4 I'm hoping someone here in this forum will solve this, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/ Share on other sites More sharing options...
bubbasheeko Posted January 4, 2009 Share Posted January 4, 2009 Hi rojo, Could you include the mysql query that you are attempting to use. Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/#findComment-729054 Share on other sites More sharing options...
rojocapo Posted January 4, 2009 Author Share Posted January 4, 2009 Here is the whole thing. The file name is AddItem.php <? require_once("../config.php"); require_once("../header.php"); require_once("access.php"); require_once("ItemsNavigation.php"); if(isset($_POST[s1])) { $MyItemTitle = strip_tags($_POST[itemTitle]); $MyItemTitle2 = stripslashes($MyItemTitle); $NewYearInfo = explode("|", $_POST[YearInfo]); $NewCategoryInfo = explode("|", $_POST[CategoryInfo]); $NewText = strip_tags($_POST[itemText]); $NewText2 = stripslashes($NewText); $NewIn = strip_tags($_POST[ingredients]); $NewIn2 = stripslashes($NewIn); $ImageName = $_FILES[itemImage][name]; if(empty($MyItemTitle)) { $add_error = "<center><font color=red size=2><b>Enter the $main_keyword title, please!</b></font></center>"; } elseif(empty($_POST[YearInfo])) { $add_error = "<center><font color=red size=2><b>Select the $main_keyword year, please!</b></font></center>"; } elseif(empty($_POST[CategoryInfo])) { $add_error = "<center><font color=red size=2><b>Select the $main_keyword category, please!</b></font></center>"; } else { $t = time(); //upload the image if(!empty($ImageName)) { $NewImageName = "$t$ImageName"; copy($_FILES[itemImage][tmp_name], "../items_images/$NewImageName"); $MainType = "P"; } else { $MainType = "T"; } //update the database $q1 = "insert into dd_items set ItemTitle = '$MyItemTitle', ItemYear = '$NewYearInfo' ItemCategory = '$NewCategoryInfo', ItemText = '$NewIn|$NewText', ItemImage = '$NewImageName', Contributor = 'n/a', DateAdded = '$t', ItemType = '$MainType' "; mysql_query($q1) or die(mysql_error()); //get the ItemID $LastID = mysql_insert_id(); //get the year name $q3 = "select YearName from dd_year where YearID = '$NewYearInfo' "; $r3 = mysql_query($q3) or die(mysql_error()); $a3 = mysql_fetch_array($r3); $DisplayYear = $a3; //get the category name $q2 = "select CategoryName from dd_categories where CategoryID = '$NewCategoryInfo' "; $r2 = mysql_query($q2) or die(mysql_error()); $a2 = mysql_fetch_array($r2); $DisplayCategory = $a2; ?> <form method=post action=AddItem.php> <table align=center width=440> <tr> <td valign=top align=left> <font color=black face=verdana size=2><b><?=$MyItemTitle2?></b></font> <br> <font color=black face=verdana size=1><b>Year: <?=$DisplayYear?></b></font> <br><br> <font color=black face=verdana size=1><b>Category: <?=$DisplayCategory?></b></font> <br><br> <table width=440> <tr> <? if(!empty($NewImageName)) { echo "<td align=center valign=top width=100><center><img src=\"../items_images/$NewImageName\" width=100></center></td>\n\t<td>"; echo nl2br($NewIn2)."<br><br>"; echo nl2br($NewText2); echo "</td>"; } else { echo "<td>"; echo nl2br($NewIn2)."<br><br>"; echo nl2br($NewText2); echo "</td>"; } ?> </tr> </table> </td> </tr> <input type=hidden name="Image" value="<?=$NewImageName?>"> <input type=hidden name="ItemID" value="<?=$LastID?>"> <tr> <td colspan=2 align=center><br><br> <table align=center width=100%> <tr> <td align=center valign=top><input type=submit name=s2 value="Accept"></td> <td align=center valign=top><input type=submit name=s2 value="Delete"></form></td> <td align=center valign=top> <form method=post action=EditItem.php> <input type=hidden name="ItemID" value="<?=$LastID?>"> <input type=hidden name="ItemType" value="<?=$MainType?>"> <input type=submit name=s10 value="Edit"> </form> </td> </tr> </table> </td> </tr> </table> <input type=hidden name="Image" value="<?=$NewImageName?>"> <input type=hidden name="ItemID" value="<?=$LastID?>"> </form> </body> </html> <? exit(); } } elseif(isset($_POST[s2])) { if($_POST[s2] == "Accept") { $q1 = "update dd_items set ItemStatus = 'approved' where ItemID = '$_POST[itemID]' "; mysql_query($q1) or die(mysql_error()); echo "<br><br><center>The new Item was added successfully.</center>"; } if($_POST[s2] == "Delete" ) { mysql_query("delete from dd_items where ItemID = '$_POST[itemID]' ") or die(mysql_error()); if(!empty($_POST[NewImageName])) { unlink("items_images/$_POST[NewImageName]"); } } } //get the year list $q3 = "select * from dd_year order by YearName "; $r3 = mysql_query($q3); if(!$r3) { header("location:../error1.php"); } else { if(mysql_num_rows($r3) == '0') { echo "<br><br><center>You need to add some categories, before adding Items.</center>"; exit(); } else { $MySelect = "<select name=YearInfo>\n\t"; $MySelect .= "<option value=\"\"></option>\n\t"; while($a3 = mysql_fetch_array($r3)) { { $MySelect .= "<option value=\"$a3[YearID]|\">$a3[YearName]</option>\n\t"; } } $MySelect .= "</select>"; } } //get the categories list $q2 = "select * from dd_categories order by CategoryName "; $r2 = mysql_query($q2); if(!$r2) { header("location:../error1.php"); } else { if(mysql_num_rows($r2) == '0') { echo "<br><br><center>You need to add some categories, before adding Items.</center>"; exit(); } else { $MySelect2 = "<select name=CategoryInfo>\n\t"; $MySelect2 .= "<option value=\"\"></option>\n\t"; while($a2 = mysql_fetch_array($r2)) { { $MySelect2 .= "<option value=\"$a2[CategoryID]|\">$a2[CategoryName]</option>\n\t"; } } $MySelect2 .= "</select>"; } } ?> <form method=post action=AddItem.php enctype="multipart/form-data"> <table align=center width=450> <caption align=center><b>Add a new <?=$main_keyword?></b><br><?=$add_error?></caption> <tr> <td align=right><?=$MainFirst?> Title:</td> <td><input type=text name=ItemTitle value="<?=$_POST[itemTitle]?>"></td> </tr> <tr> <td align=right>Year:</td> <td> <?=$MySelect?> </td> </tr> <tr> <td align=right>Category:</td> <td> <?=$MySelect2?> </td> </tr> <tr> <td valign=top align=right>Comments:</td> <td><textarea rows=6 cols=30 name=ItemText><?=$_POST[itemText]?></textarea></td> </tr> <tr> <td align=right>Image:</td> <td><input type=file name=ItemImage></td> </tr> <tr> <td colspan=2> <input type=submit name=s1 value="Preview"> </td> </tr> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/#findComment-729095 Share on other sites More sharing options...
xtopolis Posted January 4, 2009 Share Posted January 4, 2009 You missed the , before it $q1 = "insert into dd_items set ItemTitle = '$MyItemTitle', ItemYear = '$NewYearInfo', // HERE ItemCategory = '$NewCategoryInfo', ItemText = '$NewIn|$NewText', ItemImage = '$NewImageName', Contributor = 'n/a', DateAdded = '$t', ItemType = '$MainType' "; Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/#findComment-729102 Share on other sites More sharing options...
rojocapo Posted January 4, 2009 Author Share Posted January 4, 2009 Thanks, I'm testing it right now. Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/#findComment-729104 Share on other sites More sharing options...
rojocapo Posted January 4, 2009 Author Share Posted January 4, 2009 It worked, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/#findComment-729106 Share on other sites More sharing options...
bubbasheeko Posted January 4, 2009 Share Posted January 4, 2009 lol...okay...i was just going to say that lol Quote Link to comment https://forums.phpfreaks.com/topic/139386-solved-sql-syntax-error/#findComment-729112 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.