Jump to content

Photo Upload Not working!!


sblake161189

Recommended Posts

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
Share on other sites

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
Share on other sites

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
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.