Jump to content

[SOLVED] Wrong SQL syntax???


jacko_162

Recommended Posts

i get the following error when trying to submit this form.

 

can anyone help me please?!

 

<?php
include"includes/header.php";
include("connect.php");

if (isset($submit)) {

$name = $_POST['name'];
$make = $_POST['make'];
$catagory = $_POST['catagory'];
$price = $_POST['price'];
$description = $_POST['description'];
$sold = $_POST['sold'];
$colour = $_POST['colour'];
$cotw = $_POST['cotw'];

$sql = "UPDATE products SET name='$name', make='$make' catagory='$catagory' price='$price' description='$description' sold='$sold' colour='$colour' cotw='$cotw' WHERE ID='$ID'";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());

$upload_dir = "../images/products/";

$insert_id = $ID;

if (!empty($imageOne))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageOne']['type'] != "image/jpeg" && $_FILES['imageOne']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image One. Type found : " . $_FILES['imageOne']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "one.jpg";

	if (!copy($_FILES['imageOne']['tmp_name'], $upload_dir . $new_image_name))
	{
		// file uploaded add to table row
		die("Unable to upload Image One");
	}
}
}

if (!empty($imageTwo))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageTwo']['type'] != "image/jpeg" && $_FILES['imageTwo']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image Two. Type found : " . $_FILES['imageTwo']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "two.jpg";

	if (!copy($_FILES['imageTwo']['tmp_name'], $upload_dir . $new_image_name))
	{
		die("Unable to upload Image Two");
	}
}
}

if (!empty($imageThree))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageThree']['type'] != "image/jpeg" && $_FILES['imageThree']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image Three. Type found : " . $_FILES['imageThree']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "three.jpg";

	if (!copy($_FILES['imageThree']['tmp_name'], $upload_dir . $new_image_name))
	{
		die("Unable to upload Image Three");
	}
}
}

if (!empty($imageFour))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageFour']['type'] != "image/jpeg" && $_FILES['imageFour']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image Four. Type found : " . $_FILES['imageFour']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "four.jpg";

	if (!copy($_FILES['imageFour']['tmp_name'], $upload_dir . $new_image_name))
	{
		die("Unable to upload Image Four");
	}
}
}

if (!empty($imageFive))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageFive']['type'] != "image/jpeg" && $_FILES['imageFive']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image Five. Type found : " . $_FILES['imageFive']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "five.jpg";

	if (!copy($_FILES['imageFive']['tmp_name'], $upload_dir . $new_image_name))
	{
		die("Unable to upload Image Five");
	}
}
}


if (!empty($imageSix))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageSix']['type'] != "image/jpeg" && $_FILES['imageSix']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image Six. Type found : " . $_FILES['imageSix']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "six.jpg";

	if (!copy($_FILES['imageSix']['tmp_name'], $upload_dir . $new_image_name))
	{
		die("Unable to upload Image Six");
	}
}
}

if (!empty($imageThumb))
{
// we have an image in image one check we have a valid type (jpeg only ?)
if ($_FILES['imageThumb']['type'] != "image/jpeg" && $_FILES['imageThumb']['type'] != "image/pjpeg")
{
	die("Image type is not allowed for Image Thumb. Type found : " . $_FILES['imageThumb']['type']);
}
else
{
	// valid image make up a new filename
	$new_image_name = $insert_id . "thumb.jpg";

	if (!copy($_FILES['imageThumb']['tmp_name'], $upload_dir . $new_image_name))
	{
		die("Unable to upload Image Thumb");
	}
}
}





// check if we need to delete any images
if ($imageOneDelete == "yes")
{
// delete image one
unlink($upload_dir . $insert_id . "one.jpg");
}

if ($imageTwoDelete == "yes")
{
// delete image two
unlink($upload_dir . $insert_id . "two.jpg");
}

if ($imageThreeDelete == "yes")
{
// delete image three
unlink($upload_dir . $insert_id . "three.jpg");
}

if ($imageFourDelete == "yes")
{
// delete image three
unlink($upload_dir . $insert_id . "four.jpg");
}

if ($imageFiveDelete == "yes")
{
// delete image three
unlink($upload_dir . $insert_id . "five.jpg");
}

if ($imageSixDelete == "yes")
{
// delete image three
unlink($upload_dir . $insert_id . "six.jpg");
}

if ($imageThumbDelete == "yes")
{
// delete image three
unlink($upload_dir . $insert_id . "thumb.jpg");
}

echo "<BR><table width=700 border=0 align=center cellpadding=0 cellspacing=0>
  <tr class=table3> 
    <td><table width=100% border=0 cellspacing=1 cellpadding=3 align=center>
        <tr class=table1 align=center> 
          <td><b>Database Updated.</b></td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>";
} else {

$sql				= "SELECT * FROM $table1 WHERE ID='$ID'";
$query			= mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
$result			= mysql_fetch_array($query);
$catagory		= stripslashes($result["catagory"]);
$make			= stripslashes($result["make"]);
$name			= stripslashes($result["name"]);
$price			= stripslashes($result["price"]);
$description	= stripslashes($result["description"]);
$colour			= stripslashes($result["colour"]);
$sold			= stripslashes($result["sold"]);
$cotw		    = stripslashes($result["cotw"]);



// check what images exist

$images_dir = "../images/products/";

// check for image one
if (file_exists($images_dir . $ID . "one.jpg"))
{
$imageOneExists = 1;
}

// check for image two
if (file_exists($images_dir . $ID . "two.jpg"))
{
$imageTwoExists = 1;
}

// check for image three
if (file_exists($images_dir . $ID . "three.jpg"))
{
$imageThreeExists = 1;
}

// check for image three
if (file_exists($images_dir . $ID . "four.jpg"))
{
$imageFourExists = 1;
}

// check for image three
if (file_exists($images_dir . $ID . "five.jpg"))
{
$imageFiveExists = 1;
}

// check for image three
if (file_exists($images_dir . $ID . "six.jpg"))
{
$imageSixExists = 1;
}

// check for image three
if (file_exists($images_dir . $ID . "thumb.jpg"))
{
$imageThumbExists = 1;
}

?> 


<FORM name=myform method=post action="<? echo $PHP_SELF ?>" enctype="multipart/form-data">
  <table wIDth="700" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr class=table3>
      <td><table wIDth="100%" border="0" cellspacing="1" cellpadding="3" align="center">
          <tr>
            <td>Catagory:</td>
            <td width="31%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
              <select name="catagory2" size="1">
                <option value=<?php echo $catagory; ?>> <?php echo $catagory; ?> </option>
                <option value=" ">-----------------</option>
                <?  
// Query to pull information from the "catagory" Database  
$result = mysql_query("select * from $table13 order by id DESC");  
while ($row = mysql_fetch_object($result)){  
?>
                <option value=<?php echo $row->name; ?>> <?php echo $row->name; ?>
                <?}?>
                </option>
              </select>
            </font></td>
            <td width="21%">Manufacturer:</td>
            <td width="30%"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
              <select name="make2" size="1">
                <option value=<?php echo $make; ?>> <?php echo $make; ?> </option>
                <option value=" ">-----------------</option>
                <?  
// Query to pull information from the "manufacturer" Database  
$result = mysql_query("select * from $table2 order by id DESC");  
while ($row = mysql_fetch_object($result)){  
?>
                <option value=<?php echo $row->make; ?>> <?php echo $row->make; ?>
                <?}?>
                </option>
              </select>
            </font><font style="text"> </font></td>
          </tr>
          <tr>
            <td valign="top">Product Name:</td>
            <td colspan="3"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
              <input type="Text" name="name2" value="<?php echo $name ?>" size="20">
            </font></td>
          </tr>
          
          <tr class=table2> 
            <td wIDth="18%" valign="top"><b>DESCRIPTION:</b></td>
            <td colspan="3"><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
              <textarea name="description" cols="71" rows="6"><?php echo $description ?></textarea>
            </font></td>
          </tr>
			  <tr>
                    <td> </td>
			    <td> </td>
			    <td><font style="text">Colour: </font></td>
			    <td><font style="text"> </font><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
                      <input type="Text" name="colour2" value="<?php echo $colour ?>" size="20">
                    </font></td>
      </tr>
			  <tr>
                    <td><font style="text" color="#FF0000"><b>Price: </b></font></td>
			    <td><font style="text"> </font><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
                      <input type="Text" name="price2" value="<?php echo $price ?>" size="20">
                    </font></td>
			    <td> </td>
			    <td> </td>
      </tr>
			  <tr>
                    <td> </td>
			    <td> </td>
			    <td> </td>
			    <td> </td>
      </tr>
			  <tr>
                    <td> </td>
			    <td> </td>
			    <td>Sold:</td>
			    <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
                      <select name="sold2" size="1">
                        <option value=<?php echo $sold ?>> <?php echo $sold ?> </option>
                        <option value=" ">-----------------</option>
                        <?  
// Query to pull information from the "sold" Database  
$result = mysql_query("select * from sold order by id DESC");  
while ($row = mysql_fetch_object($result)){  
?>
                        <option value=<?php echo $row->sold; ?>> <?php echo $row->sold; ?>
                        <?}?>
                        </option>
                      </select>
                    </font></td>
      </tr>
			  <tr>
                    <td>Product of the week:</td>
			    <td><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
                      <select name="cotw" size="1">
                        <option value=<?php echo $cotw ?>> <?php echo $cotw ?> </option>
                        <option value=" ">-----------------</option>
                        <?  
// Query to pull information from the "sold" Database  
$result = mysql_query("select * from sold order by id DESC");  
while ($row = mysql_fetch_object($result)){  
?>
                        <option value=<?php echo $row->sold; ?>> <?php echo $row->sold; ?>
                        <?}?>
                        </option>
                      </select>
                    </font></td>
			    <td> </td>
			    <td> </td>
      </tr>
          
          <tr class=table2> 
            <td valign=top>IMAGES:</td>
            <td colspan="3">
            	1: <?
            	if ($imageOneExists) {
            	?> Replace : <input name="imageOne" type="file" class="bginput" id="imageOne">
            	Delete : <input type="checkbox" name="imageOneDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>one.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageOne" type="file" class="bginput" id="imageOne">
            	<? } ?>
             	<br>
            	2: <?
            	if ($imageTwoExists) {
            	?> Replace : <input name="imageTwo" type="file" class="bginput" id="imageTwo">
            	Delete : <input type="checkbox" name="imageTwoDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>two.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageTwo" type="file" class="bginput" id="imageTwo">
            	<? } ?>
            	<br>
            	3: <?
            	if ($imageThreeExists) {
            	?> Replace : <input name="imageThree" type="file" class="bginput" id="imageThree">
            	Delete : <input type="checkbox" name="imageThreeDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>three.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageThree" type="file" class="bginput" id="imageThree">
            	<? } ?>
            	<br>
            	4: <?
            	if ($imageFourExists) {
            	?> Replace : <input name="imageFour" type="file" class="bginput" id="imageFour">
            	Delete : <input type="checkbox" name="imageFourDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>four.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageFour" type="file" class="bginput" id="imageFour">
            	<? } ?>
			            	<br>
            	5: <?
            	if ($imageFiveExists) {
            	?> Replace : <input name="imageFive" type="file" class="bginput" id="imageFive">
            	Delete : <input type="checkbox" name="imageFiveDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>five.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageFive" type="file" class="bginput" id="imageFive">
            	<? } ?>
			            	<br>
            	6: <?
            	if ($imageSixExists) {
            	?> Replace : <input name="imageSix" type="file" class="bginput" id="imageSix">
            	Delete : <input type="checkbox" name="imageSixDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>six.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageSix" type="file" class="bginput" id="imageSix">
            	<? } ?>
			            	<br>
            	7: <?
            	if ($imageThumbExists) {
            	?> Replace : <input name="imageThumb" type="file" class="bginput" id="imageThumb">
            	Delete : <input type="checkbox" name="imageThumbDelete" value="yes">
           		<a target="_new" href="../gfx/cars/<? echo $ID ?>thumb.jpg">View</a>
            	<? } else {
            	?> Upload : <input name="imageThumb" type="file" class="bginput" id="imageThumb">
            	<? } ?>
              - Thumbnail Image</td>
          </tr>
          
          <!-- end of new code -->
          <tr class=table1> 
            <td colspan="4" align="center" valign="top"> <input type="Submit" name="submit" value="Done!" class="bginput"><input type="hidden" name="ID" value="<?php echo $ID; ?>">
              <input type="reset" name="reset" value="Reset" class="bginput">            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</FORM>

<?php
}
?>
<? include("includes/footer.php") ?>

 

Aprreciate any help please?!

Link to comment
Share on other sites

sorry thought i posted :(

 

"Cannot query the database.

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 'catagory='' price='' description='' sold='' colour='' cotw='' W"

 

thats what i get :(

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.