TCombs Posted April 16, 2014 Share Posted April 16, 2014 I had help last year creating a very basic store that simply shows products, an image for the product, price, etc. No financial information is being input on the site. The admin of the site can go in and add new products, along with their image. The site worked fine for the last year, now suddenly, they can't upload images. When an admin tried to upload an image for a product, this is the error I'm getting: 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 'image = ', B6405 Thumb.jpg' WHERE id = '64'' at line 1 When I look at the console in Firefox when executing the upload command, this is what I see: <br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/content/93/7468893/html/adminprodupdate.php</b> on line <b>73</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/content/93/7468893/html/adminprodupdate.php:73) in <b>/home/content/93/7468893/html/adminprodupdate.php</b> on line <b>82</b><br /> This is the code for the adminprodupdate.php file referenced above, Can someone please take a look at the code and let me know if they see anything obvious? <?php include("config.php"); include("db.php"); include("functions.php"); $id=$_POST['id']; $active=$_POST['active']; $cat_id=$_POST['cat_id']; $name=$_POST['name']; $description=$_POST['description']; $details=$_POST['details']; $price7=$_POST['price7']; $price=$_POST['price']; $price2=$_POST['price2']; $price3=$_POST['price3']; $price4=$_POST['price4']; $price5=$_POST['price5']; $price6=$_POST['price6']; $minimum=$_POST['minimum']; $arrsizes = $_POST['size']; $arrcolors = $_POST['color']; $image1=$_POST['image']; $image2=$_POST['image2']; $image_directory = $_SERVER['DOCUMENT_ROOT'] . '/store-images/'; $image1 = false; $image2 = false; if (is_uploaded_file($_FILES['image']['tmp_name'])) { ProcessImageUpload('image', $image_directory); $image1_name = $_FILES['image']['name']; $image1 = true; } if (is_uploaded_file($_FILES['image2']['tmp_name'])) { ProcessImageUpload('image2', $image_directory); $image2_name = $_FILES['image2']['name']; $image2 = true; } $sql="UPDATE products SET active = '$active', cat_id = '$cat_id', name = '$name', description = '$description', details = '$details', price7 = '$price7', price = '$price', price2 = '$price2', price3 = '$price3', price4 = '$price4', price5 = '$price5', price6 = '$price6', minimum = '$minimum'"; if ($image1) { $sql .= "image = ', $image1_name'"; } if ($image2) { $sql .= "image2 = ', $image2_name'"; } $sql .= " WHERE id = '$id'"; mysql_query($sql) or die ("Error: ".mysql_error()); $result = mysql_query("SELECT id FROM products ORDER BY id DESC LIMIT 0,1"); if ($row = mysql_fetch_assoc($result)) { $productid = $row['$id']; } mysql_query("DELETE FROM productoptions WHERE productid='$id'"); foreach ($arrsizes as $sizevalue) { foreach ($arrcolors as $colorvalue) { $sql2 = "INSERT INTO productoptions (productid, sizeid, colorid) VALUES ('$id', '$sizevalue', '$colorvalue')"; mysql_query($sql2) or die("Error: ".mysql_error()); } } header("Location: " . $config_basedir . "adminhome.php"); ?> Thank you in advance! If I didn't explain thoroughly, please let me know. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted April 16, 2014 Share Posted April 16, 2014 (edited) Don't see your upload script for your first error, but it seems you have an extra comma image = ', B6405 Thumb.jpg' Then the id value should be wrapped single quotes and entire query wrapped with double quotes, you seem to have had 2 single quotes at the end. WHERE id = '64'" As for your second set of errors... you are trying to loop through what is expected to be an array, but above on line 21 you set $arrsizes = $_POST['size']; and same for the line 73 which is $arrcolors, on line 22 you have set as $arrcolors = $_POST['color']; header errors are appearing because your error messages are output before header can be sent, that will go away if have no errors or disable any error reporting. Edited April 16, 2014 by QuickOldCar Quote Link to comment Share on other sites More sharing options...
TCombs Posted April 16, 2014 Author Share Posted April 16, 2014 Thanks for your response. Here is the upload function from the functions.php file function ProcessImageUpload($field, $image_destination) { //Your Image $imgSrc = $_FILES[$field]['tmp_name']; $imgName = $_FILES[$field]['name']; //getting the image dimensions list($width, $height) = getimagesize($imgSrc); //save original image move_uploaded_file($imgSrc, $image_destination . $imgName); } Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted April 16, 2014 Share Posted April 16, 2014 Shouldn't these be... if ($image1) { $sql .= " , image = '$image1_name'"; } if ($image2) { $sql .= " , image2 = '$image2_name'"; } Quote Link to comment Share on other sites More sharing options...
TCombs Posted April 16, 2014 Author Share Posted April 16, 2014 Shouldn't these be... if ($image1) { $sql .= " , image = '$image1_name'"; } if ($image2) { $sql .= " , image2 = '$image2_name'"; } Yes, Thank you!! That fixed it! Thanks again!!! Quote Link to comment 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.