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 4058364
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:04:13+00:00 2026-05-20T15:04:13+00:00

I am trying to submit data to a database. I have an update form

  • 0

I am trying to submit data to a database. I have an update form that has several fields on it that pulls data from the database into the fields. Submitting it updates the data in the database. The two fields i am concerned with our two image uploaders that i have in the form. I have been doing this successfully when i have only one image uploader on the page, but can’t wrap my head around the conditional syntax when i add the second one. Below is the code that i am using for the forms that have only one image uploader. It looks to see if that submitted element is empty. If so, it runs an update statement and leaves out the image variable. If the image variable is not empty it runs an update statement with that field added to the statement.

if($imgProfileFull == ""){
$query = "update students set `nameFirst` = '$nameFirst', `nameLast` = '$nameLast', `profile` = '$profile', `priority` = '$priority', `active` = '$active', `_modifiedDate` = '$_modifiedDate' where `id` = '$id'";
}else{
if((($_FILES["image"]["type"] == "image/jpeg")
|| ($_FILES["image"]["type"] == "image/pjpeg"))
&& ($_FILES["image"]["size"] < 500000))
{
  if($_FILES["image"]["error"] > 0){
    header("location:students.php?file=error");
  }else{
    move_uploaded_file($_FILES["image"]["tmp_name"],
    "../images/students/full/" . $imgProfileFull);
  }
}else{
  header("location:students.php?file=error");
}
$query = "update students set `imgProfileFull` = '$imgProfileFull', `nameFirst` = '$nameFirst', `nameLast` = '$nameLast', `profile` = '$profile', `priority` = '$priority', `active` = '$active', `_modifiedDate` = '$_modifiedDate' where `id` = '$id'";
}

How would i write my update statement to include another image field. The variable would be $imgProfileThumb. Basically i want to update the two image columns in the database if, and only if, they are NOT empty. This is because the way the form is built, the image field is technically always empty unless an image actually gets uploaded. Any thoughts? Thanks!!

  • 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-20T15:04:13+00:00Added an answer on May 20, 2026 at 3:04 pm

    You can use an if statement to create your query dynamically.

    $query = "UPDATE students SET ";
    
    if ($imgProfileFull !== ""){
        $query .= "`imgProfileFull` = '$imgProfileFull', ";
    }
    
    if ($imgProfileThumb !== ""){
        $query .= "`imgProfileThumb` = '$imgProfileThumb', ";
    }
    
    $query .= "`nameFirst` = '$nameFirst',
               `nameLast` = '$nameLast',
               `profile` = '$profile',
               `priority` = '$priority',
               `active` = '$active',
               `_modifiedDate` = '$_modifiedDate'
               WHERE `id` = '$id'";
    

    You may also wish to use mysql_real_escape_string for your string data if you are not already doing so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that is trying to insert some data into an SQL
I've been trying to submit a form with the FormPanel using the Action class
I'm trying to submit a form with javascript. Firefox works fine but IE complains
Well I am trying to submit a form by pressing enter but not displaying
I have an ASP.NET MVC application that uses LINQ2SQL as the database layer. I
I'm trying to use form submit with jquery without a page refresh as demonstrated
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to make a make generic select control that I can dynamically add elements
Trying to make a MySQL-based application support MS SQL, I ran into the following
I am working on an application that will have online and offline components and

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.