Jump to content

Insert name into DB when uploading an image


harkly

Recommended Posts

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());
}

Archived

This topic is now archived and is closed to further replies.

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