yandoo Posted March 12, 2008 Share Posted March 12, 2008 Hi there, I am trying to update a record in my database by adding an image to it. A simple form allows the user to upload an image which goes to a folder and a link to the image is added to the record in the database. It doesnt appear to be working??? I get the error: Notice: Undefined index: image in C:\wamp\www\Woodside\latestTESTv2.php on line 11 Notice: Undefined index: image in C:\wamp\www\Woodside\latestTESTv2.php on line 12 Notice: Undefined index: image in C:\wamp\www\Woodside\latestTESTv2.php on line 13 Notice: Undefined index: image in C:\wamp\www\Woodside\latestTESTv2.php on line 15 Here is some more debugging info:Array ( ) These lines of code that it points to is: $image_name = $_FILES['image']['name']; $image_size = $_FILES['image']['size']; $image_type = $_FILES['image']['type']; $uploadfile = $file_dir.basename($image_name); if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { None of the image details(name, size, type) are printed on screen either??? Help me... please ??? ini_set('display_errors', '1'); //image upload test $file_dir = "C:/wamp/www/Woodside/Images/"; $link_dir = "./Images/"; $file_url = "http://localhost/woodside/Images/"; function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); { $image_name = $_FILES['image']['name']; $image_size = $_FILES['image']['size']; $image_type = $_FILES['image']['type']; $uploadfile = $file_dir.basename($image_name); if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $updateSQL = sprintf("UPDATE animal SET Image=('".$link_dir.$image_name."') WHERE AnimalID=%s", //GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['panimal'], "int")); mysql_select_db($database_woodside, $woodside); $Result1 = mysql_query($updateSQL, $woodside) or die(mysql_error()); $updateGoTo = "latestTESTv2.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } //Uncomment these lines if you are having problems echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; print "<center>Image path: $file_dir<br>\n"; print "<center>Image name: $image_name<br>\n"; print "<center>Image size: $image_size bytes<br>\n"; print "<center>Image type: $image_type<p><br>\n\n"; print "<img src=\"$file_url/$image_name\"><p>\n\n"; <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form name="form1" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data"><br/> <input type="hidden" name="MAX_FILE_SIZE" value="100000"> <input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br> <input type="submit" name=submit value="Submit"> <input name="panimal" type="hidden" value="<?php echo $row_animal['AnimalID']; ?>" /> <input type="hidden" name="MM_update" value="form1"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 12, 2008 Share Posted March 12, 2008 what is the purpose the open and close braces either side of the code <?php if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); { //whats this for?? $image_name = $_FILES['image']['name']; $image_size = $_FILES['image']['size']; $image_type = $_FILES['image']['type']; $uploadfile = $file_dir.basename($image_name); if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } } //and this one which is the closing brace?? ?> I think you need to look closly where your opening and closes braces are because the if statement at the start of the aboce code does not have a closing brace Quote Link to comment Share on other sites More sharing options...
yandoo Posted March 12, 2008 Author Share Posted March 12, 2008 Hello, Thanks for the reply I have had look at the braces and modified it....Now no errors appear!!! The images are loaded to the folder, however there is no link being inserted into the record in the database. So im thinking theres perhaps an error with this line of code: "UPDATE animal SET Image=('".$link_dir.$image_name."') WHERE AnimalID=%s", GetSQLValueString($_POST['image'], "text"), Because the image name link is not inserted into the record... Is there something with the way the above code is writen??? Thanks Here the modified code: <?php require_once('Connections/woodside.php'); ?> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); //image upload test $file_dir = "C:/wamp/www/Woodside/Images/"; $link_dir = "./Images/"; $file_url = "http://localhost/woodside/Images/"; function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) { $image_name = $_FILES['image']['name']; $image_size = $_FILES['image']['size']; $image_type = $_FILES['image']['type']; $uploadfile = $file_dir.basename($image_name); if (move_uploaded_file($_FILES['image']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; $updateSQL = sprintf("UPDATE animal SET Image=('".$link_dir.$image_name."') WHERE AnimalID=%s", GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['panimal'], "int")); mysql_select_db($database_woodside, $woodside); $Result1 = mysql_query($updateSQL, $woodside) or die(mysql_error()); print "</pre>"; print "<center>Image path: $file_dir<br>\n"; print "<center>Image name: $image_name<br>\n"; print "<center>Image size: $image_size bytes<br>\n"; print "<center>Image type: $image_type<p><br>\n\n"; print "<img src=\"$file_url/$image_name\"><p>\n\n"; } else { echo "Possible file upload attack!\n"; } //Uncomment these lines if you are having problems echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; print "<center>Image path: $file_dir<br>\n"; print "<center>Image name: $image_name<br>\n"; print "<center>Image size: $image_size bytes<br>\n"; print "<center>Image type: $image_type<p><br>\n\n"; print "<img src=\"$file_url/$image_name\"><p>\n\n"; $updateGoTo = "latestTESTv2.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form name="form1" action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data"><br/> <input type="hidden" name="MAX_FILE_SIZE" value="100000"> <input type="file" accept=".jpg" size="20" name="image" title="Image Upload" /><br> <input type="submit" name=submit value="Submit"> <input name="panimal" type="hidden" value="<?php echo $row_animal['AnimalID']; ?>" /> <input type="hidden" name="MM_update" value="form1"> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
paul2463 Posted March 13, 2008 Share Posted March 13, 2008 i am not sure about this but you could try this $updateSQL = sprintf("UPDATE animal SET Image='$link_dir.$image_name' WHERE AnimalID=%s", GetSQLValueString($_POST['image'], "text"), GetSQLValueString($_POST['panimal'], "int")); [code=php:0] Quote Link to comment Share on other sites More sharing options...
yandoo Posted March 15, 2008 Author Share Posted March 15, 2008 Hi there, Thaks for the reply! I managed to get it working with slight tweak... $updateSQL = sprintf("UPDATE animal SET Image='%s' WHERE AnimalID=%u", $link_dir.$image_name, GetSQLValueString($_POST['panimal'], "int")); Thats brill, worksa charm Thanks You 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.