Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7650735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:19:45+00:00 2026-05-31T11:19:45+00:00

Ok, this one is driving me nuts. I have a backend file uploader that

  • 0

Ok, this one is driving me nuts. I have a backend file uploader that uploads .jpg files to the server. Then I want to upload the filename(s) of the .jpgs to my database. So when the page loads I can add the filename from the database and the pictures will display on the page. This works fine, but I also need to be able to update the files and the filenames in the database. If the user changes all the files and file names everything is fine. But if the user wishes to change only one or two file(s) and filename(s) the MySql update statement ends up having some of the variables empty thereby effectively deleting the existing filenames in the record instead of leaving them alone. As usual I have searched stackoverflow and google before asking for help and I have not found anything that is really pertinent. Here is the applicable code.

<?php 
 session_start();
 $id = $_SESSION['id'];

 //This is the directory where images will be saved 
 $target = "imgs/"; 
// "http://www.surfcup.com/travel_site/images/ ";

 $targetlogo = $target . basename( $_FILES['imageLogo']['name']);
 $targetpic1 = $target . basename( $_FILES['image1']['name']);
 $targetpic2 = $target . basename( $_FILES['image2']['name']);
 $targetpic3 = $target . basename( $_FILES['image3']['name']);
 $targetpic4 = $target . basename( $_FILES['image4']['name']);
 $targetpic5 = $target . basename( $_FILES['image5']['name']);

 //This gets all the other information from the form 

 $logo=($_FILES['imageLogo']['name']); 
 $pic1=($_FILES['image1']['name']); 
 $pic2=($_FILES['image2']['name']); 
 $pic3=($_FILES['image3']['name']); 
 $pic4=($_FILES['image4']['name']); 
 $pic5=($_FILES['image5']['name']); 


 // Connects to Database 
 mysql_connect("localhost", "surfcup_HotAdmin","password") or die ('I cannot connect to        the database because: ' .mysql_error());
 mysql_select_db("surfcup_hotels") or die('I cannot connect to the database because: .mysql_error());

 $query="UPDATE Hotels
 SET 
 hotel.imageLogo = '".$logo."',
 hotel.image1 = '".$pic1."',
 hotel.image2 = '".$pic1."',
 hotel.image3 ='".$pic1."',
 hotel.image4 = '".$pic1."',
 hotel.image5 = '".$pic1."'
 WHERE Hotels.id='".$id."'";


 mysql_query($query) or die ('Error Updating Hotel '.mysql_error());

//stuff to upload the files below



?>

I think I either need to check if the variables are null and somehow not up load them or stop the database from accepting null entries. The later though would make the user have to add 6 files when he/she creates a record. What if they only had 5 or 3? I can’t seem to get my head around how I would check if the variables are null and only upload the ones with filenames in them in the UPLOAD statement. Thanks again, in advance, for all your help.
Dave

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:19:46+00:00Added an answer on May 31, 2026 at 11:19 am

    You can try this. Basically it checks if the value is empty. If it is not, then it adds the value to the array. At the end we implode the array into a string that we will add to the your query. In the example I only did a few of the images, but you should get the point. It should work barring syntax errors in my code.

    Although I will say that this is not the best way to do it. You can definitely improve on this and make it more secure and efficient.

    $uploaded_images = array();
    
    if(!empty($logo)){
       $uploaded_images[] = "hotel.imageLogo = '".$logo."'";
    }
    
    if(!empty($pic1)){
       $uploaded_images[] = "hotel.image1 = '".$pic1."'";
    }
    
    if(!empty($pic2)){
       $uploaded_images[] = "hotel.image2 = '".$pic2."'";
    }
    
    $values_to_set = implode(', ', $uploaded_images);
    $query= "UPDATE Hotels SET " . $values_to_set . " WHERE Hotels.id='" . $id . "'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, this one is driving me nuts.... I have a string that is formed
This one has been driving me nuts. I have a div that has it's
This is driving me crazy. I have this one php file on a test
This is a dumb newbie question, but one that is driving me nuts. I
This is driving me nuts. Its a tough one to explain but I'll have
This is literally driving me nuts. I have 2 entities that use NSStrings as
I know the general guidelines to double-postbacks, but this one is driving me nuts
No luck at MSDN with this one, which is driving me nuts. I us
This one has been driving me nuts for a few days now and I've
This problem is driving me nuts. I have a prototype UITableViewCell in my storyboard.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.