sblake161189 Posted February 23, 2011 Share Posted February 23, 2011 Hey Guys, I have a php script that update's franchise information using a mysql table. Note: Ter = Territory, ie. the territory that franchise covers. <?php include('config.php'); if (isset($_GET['Ter']) ) { $ter = (int) $_GET['Ter']; if (isset($_POST['submitted'])) { //Photo Upload //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $photo =($_FILES['photo']['name']); //Pause Photo Upload foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); } $sql= "UPDATE `ter` SET `Ter` = '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' , `Theme` = '{$_POST['Theme']}' , `LocalInfo` = '{$_POST['LocalInfo']}' , `BranchInfo` = '{$_POST['BranchInfo']}' , `photo` = '{$_POST['photo']}' WHERE `Ter` = '$ter' "; mysql_query($sql) or die(mysql_error()); //Unpause Photo Upload //Writes the photo to the server move_uploaded_file($_FILES['photo']['tmp_name'], $target); //End of Photo Upload echo (mysql_affected_rows()) ? "Edited Branch.<br />" : "Nothing changed. <br />"; } $row = mysql_fetch_array ( mysql_query("SELECT * FROM `ter` WHERE `Ter` = '$ter' ")); ?> In phpmyadmin I can see my table and it has the correct image name displayed in the photo column. So you would assume its worked. But when I look in the 'images/' location no image has been uploaded. So I think there is an error with the upload part but cant figure out whats wrong. Cheers, S Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/ Share on other sites More sharing options...
Adam Posted February 23, 2011 Share Posted February 23, 2011 Take a look at $_FILES['...']['error']. Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178714 Share on other sites More sharing options...
AbraCadaver Posted February 23, 2011 Share Posted February 23, 2011 error_reporting(E_ALL); ini_set('display_errors', '1'); Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178718 Share on other sites More sharing options...
sblake161189 Posted February 23, 2011 Author Share Posted February 23, 2011 Thanks guys, If I turn on error reporting I get... ------ Notice: Undefined index: photo in /home/theacidf/public_html/aidtofreedom/admin/edit.php on line 123 Notice: Undefined index: photo in /home/theacidf/public_html/aidtofreedom/admin/edit.php on line 125 Notice: Undefined index: photo in /home/theacidf/public_html/aidtofreedom/admin/edit.php on line 137 Notice: Undefined index: photo in /home/theacidf/public_html/aidtofreedom/admin/edit.php on line 140 Nothing changed. --- So it makes more sense to you, I have explained the different line no's as there is HTML that i didnt upload earlier. Line 123 = $target = $target . basename( $_FILES['photo']['name']); Line 125 = $photo =($_FILES['photo']['name']); Line 137 = if($_FILES['photo']['error']) { Line 140 = move_uploaded_file($_FILES['photo']['tmp_name'], $target); Cheers, S Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178734 Share on other sites More sharing options...
Pikachu2000 Posted February 23, 2011 Share Posted February 23, 2011 Does your <form> tag include the enctype="multipart/form-data" attribute? Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178736 Share on other sites More sharing options...
sblake161189 Posted February 23, 2011 Author Share Posted February 23, 2011 Quote Does your <form> tag include the enctype="multipart/form-data" attribute? Ooops! No, it didnt lol Ive added it now, but it says: Notice: Undefined index: photo in /home/theacidf/public_html/aidtofreedom/admin/edit.php on line 130 Line 130 = $sql= "UPDATE `ter` SET `Ter` = '{$_POST['Ter']}' , `BranchName` = '{$_POST['BranchName']}' , `BranchAddress` = '{$_POST['BranchAddress']}' , `BranchTel` = '{$_POST['BranchTel']}' , `BranchEmail` = '{$_POST['BranchEmail']}' , `BranchLink` = '{$_POST['BranchLink']}' , `Theme` = '{$_POST['Theme']}' , `LocalInfo` = '{$_POST['LocalInfo']}' , `BranchInfo` = '{$_POST['BranchInfo']}' , `photo` = '{$_POST['photo']}' WHERE `Ter` = '$ter' "; Plus it doesn't even upload the file name and extension to the photo column nomore... hmm Cheers, S Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178741 Share on other sites More sharing options...
sblake161189 Posted February 23, 2011 Author Share Posted February 23, 2011 It doesnt like this bit I think `photo` = '{$_POST['photo']}' But its still not uploading an image to the images folder or inputing the file name into the photo column. Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178753 Share on other sites More sharing options...
sblake161189 Posted February 23, 2011 Author Share Posted February 23, 2011 SOLVED!!! `photo` = '{$_POST['photo']}' it should be... `photo` = '{$_FILES['photo']['name']}' no errors and uploads thanks anyway! Link to comment https://forums.phpfreaks.com/topic/228613-photo-upload-not-working/#findComment-1178769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.