harkly Posted March 15, 2010 Share Posted March 15, 2010 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()); } Link to comment https://forums.phpfreaks.com/topic/195250-insert-name-into-db-when-uploading-an-image/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.