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

  • Home
  • SEARCH
  • 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 3841734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:41:37+00:00 2026-05-19T15:41:37+00:00

This is an extension of a question I asked a wee while ago which

  • 0

This is an extension of a question I asked a wee while ago which @eHussain was nice enough to help out with.

I have form which inserts various details into a MySQL table and uploads a file (the name of which is also registered in the database). This works fine. The issue comes when I update, say, the name and not the image. In this case the image name is over written as ‘blank’, and rightly so as that’s the value in the file field.

The update code:

<?php
error_reporting(E_ALL^E_NOTICE);
define('INCLUDE_CHECK',true);
include "connect.php";

$target = "../uploads/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['name'];
$url=$_POST['url'];
$description=$_POST['description'];
$pic=($_FILES['photo']['name']);
$author=$_POST['author'];
$company=$_POST['company'];
$published=$_POST['published'];
$dashboardID=$_POST['dashboardID'];

//Writes the information to the database
mysql_query("UPDATE dashboard SET name='$name', url='$url', description='$description', documentName='$pic', author='$author', company='$company', publish='$published' WHERE dashboardID='$dashboardID'");

//Writes the photo to the server

if(isset($_FILES['photo']['tmp_name'])) //  check if any file is uploaded
{
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

header("Location: ../dashboard.php?success=2"); } else {

header("Location: ../dashboard.php?success=0"); }
}

?>

I understand the ‘isset’ to avoid a the error generated if no file is selected, but I don’t understand how I can extent this to avoid updating a field which has a blank value.

  • 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-19T15:41:38+00:00Added an answer on May 19, 2026 at 3:41 pm

    Do a check on the $_FILES array before running the query.

    From there, you can either dynamically build the query (including or excluding the documentName field) or alternatively, fetch the current value and assign it to $pic.

    For example (untested)

    $values = array(
        'name' => $name,
        'url'  => $url,
        // etc
    );
    
    if (isset($_FILES['photo']['name'])) {
        $values['documentName'] = $_FILES['photo']['name']
    }
    
    // mysql functions are naff, use PDO
    
    $query = 'UPDATE dashboard SET %s WHERE dashboardID = :dashboardID';
    $set = array();
    foreach (array_keys($values) as $col) {
        $set[] = sprintf('`%s` = :%s', $col, $col);
    }
    $stmt = $pdo->prepare(sprintf($query, implode(', ', $set)));
    $values['dashboardID'] = $dashboardID;
    
    $stmt->execute($values);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an extension to a question which I asked some time ago. I
This is an extension for this question asked an hour ago. We cannot modify
this is an extension to a previous question I asked , today .... which
this question is an extension to a previous question i asked (and was answered).
This is an extension of a question I previously asked here . Long story
This is an extension / next step of this question I asked a few
this is an extension of a question I asked on the Salesforce developer boards
This is a sort of extension of this question I asked yesterday (the question
I have asked this question in Radiant CMS google group, but no one answered
A form of this question has been asked and answered a gizzilion times, with

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.