scmeeker Posted July 6, 2010 Share Posted July 6, 2010 Okay, I got the other part I posted previously working. Now once the user is satisfied with addind/updating their details they move on to a new page where they will upload an image. I'm able to upload the image just fine but I'm trying to get the file name of the image to be inserted into the associated product record in the table. When I click it, it returns my image to the browser (good) and uploads it (good) but does not put the name in the product record. Here is the form action code for this page: <?php session_start (); ?> <?php ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?> <?php mysql_connect("localhost", "", "", "store") or die(mysql_error()); mysql_select_db("store") or die(mysql_error()); $item_image = $_FILES['image_upload_box']['name']; $item_id = mysql_real_escape_string($_POST[id]); $sql="UPDATE product SET image_upload_box='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { // upload the file if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) { // file needs to be jpg,gif,bmp,x-png and 4 MB max if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000)) { // some settings $max_upload_width = 500; $max_upload_height = 500; // if user chosed properly then scale down the image according to user preferances if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){ $max_upload_width = $_REQUEST['max_width_box']; } if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){ $max_upload_height = $_REQUEST['max_height_box']; } // if uploaded image was JPG/JPEG if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){ $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]); } // if uploaded image was GIF if($_FILES["image_upload_box"]["type"] == "image/gif"){ $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]); } // BMP doesn't seem to be supported so remove it form above image type test (reject bmps) // if uploaded image was BMP if($_FILES["image_upload_box"]["type"] == "image/bmp"){ $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]); } // if uploaded image was PNG if($_FILES["image_upload_box"]["type"] == "image/x-png"){ $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]); } $remote_file = "image_files/".$_FILES["image_upload_box"]["name"]; imagejpeg($image_source,$remote_file,100); chmod($remote_file,0644); // get width and height of original image list($image_width, $image_height) = getimagesize($remote_file); if($image_width>$max_upload_width || $image_height >$max_upload_height){ $proportions = $image_width/$image_height; if($image_width>$image_height){ $new_width = $max_upload_width; $new_height = round($max_upload_width/$proportions); } else{ $new_height = $max_upload_height; $new_width = round($max_upload_height*$proportions); } $new_image = imagecreatetruecolor($new_width , $new_height); $image_source = imagecreatefromjpeg($remote_file); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); imagejpeg($new_image,$remote_file,100); imagedestroy($new_image); } imagedestroy($image_source); header("Location: add_new_product4.php?id={$item_id}=success&show_image=".$_FILES["image_upload_box"]["name"]); exit; } else{ header("Location: add_new_product.php4?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error"); exit; } } } ?> It's also not holding the $item_id in the URL code from above: header("Location: add_new_product4.php?id={$item_id}=success&show_image=".$_FILES["image_upload_box"]["name"]); Any suggestions?? Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/206932-another-updating-problem/ Share on other sites More sharing options...
fenway Posted July 8, 2010 Share Posted July 8, 2010 You need to sort out if it's mysql or php that's not working. Quote Link to comment https://forums.phpfreaks.com/topic/206932-another-updating-problem/#findComment-1083067 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.