Jump to content

[SOLVED] SQL syntax error


rojocapo

Recommended Posts

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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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' ";

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.