Author Topic: Insert name into DB when uploading an image  (Read 160 times)

0 Members and 1 Guest are viewing this topic.

Offline harklyTopic starter

  • Enthusiast
  • Posts: 245
    • View Profile
Insert name into DB when uploading an image
« on: March 14, 2010, 09:37:15 PM »
I am trying to upload 5 images and then insert there names into my database. My problem is when there is only 1 or a few images selected it still puts a name in the database, how do I prevent this?

$userID="test";

$photo_1=$_POST["photo_1"];
$photo_2=$_POST["photo_2"];
$photo_3=$_POST["photo_3"];
$photo_4=$_POST["photo_4"];
$photo_5=$_POST["photo_5"];

include(
'library/login.php');
login();
mysql_select_db('test');


if (
$photo_1 != 'null')
  {


  
$extension strrchr($_FILES['photo_1']['name'],'.');  
  
$extension strtolower($extension); 

  
$photoNumber="_1";

  
$finalName="$userID$photoNumber";


  
$save_path "uploads/";

  
$target_path $save_path basename$_FILES['photo_1']['name']); 

  
$NewPhotoName $finalName

  
$withExt $NewPhotoName $extension;

  
$filename $save_path $NewPhotoName $extension

  if(
move_uploaded_file($_FILES['photo_1']['tmp_name'], $filename)) {
    echo 
"The file ".  basename$_FILES['photo_1']['name']). 
    
" has been uploaded";
  } else{
    echo 
"There was an error uploading photo #1, please try again!";
  }

$query "UPDATE photos SET photo_1='$withExt' WHERE userID='$userID'";

$result mysql_query($query) or die(mysql_error());
}