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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:44:40+00:00 2026-06-10T15:44:40+00:00

I am trying to edit a profile and have a problem with the image.

  • 0

I am trying to edit a profile and have a problem with the image.

When I create the profile, I can upload the image successfully and see the image when I view the profile.

However when I go to edit the profile, if I do not change values such as name, age etc then these get written back to the database with the unchanged / original value.

Unfortunately if the image is not changed, when the edit button is clicked, it gets overwritten with blank values.

What I am after is a way to say:

IF $FILES[] is empty
{

do not update image details

}

ELSE

{

update image details

}

My current code looks like this:

    // EDIT A PLAYER PROFILE

    if (isset($_POST['action']) and $_POST['action'] == 'Edit' )
    {
        include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
        try
        {
            // $sql = 'SELECT id, name, age, position, height, weight, satscore, gpa FROM player WHERE id = :id';
            $sql = 'SELECT player.id, player.name AS name, age, position, height, weight, previousclubs.id AS previousclubsid, GROUP_CONCAT(distinct previousclubs.name) previousclubs, 
                satscore, gpa, GROUP_CONCAT(distinct link) link, email, filename, mimetype, filedata
                FROM player INNER JOIN playerpreviousclubs
                    ON player.id = playerid
                INNER JOIN previousclubs
                    ON previousclubid = previousclubs.id
                INNER JOIN links
                    ON links.playerid = player.id
                WHERE player.id = :id';
            $s = $pdo->prepare($sql);
            $s->bindValue(':id', $_POST['id']);
            $s->execute();
        }
        catch (PDOException $e)
        {
            $error = 'Error fetching profile details.' . $e->getMessage();
            include 'error.html.php';
            exit();
        }

        $row = $s->fetch();
        $pageTitle = 'Edit Profile';
        $action = 'editform';
        $name = $row['name'];
        $age = $row['age']; 
        $position = $row['position'];
        $height = $row['height'];
        $weight = $row['weight'];
        $satscore = $row['satscore'];
        $gpa = $row['gpa'];
        $previousclubs = $row['previousclubs'];
        $previousclubsid = $row['previousclubsid'];
        $link = $row['link'];
        $email = $row['email'];
        $filename = $row['filename'];
        $mimetype = $row['mimetype'];
        $filedata = $row['filedata'];*/
        $id = $row['id'];
        $button = 'Update Profile';

        include 'addplayerprofile.html.php';
        exit();
    }

    if (isset($_GET['editform']))
    {
        include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';

        // UPDATE MAIN PLAYER PROFILE DETAILS
        try
        {
            $sql = "UPDATE player SET
                name = :name,
                age = :age,
                position = :position,
                height = :height,
                weight = :weight,
                satscore = :satscore,
                gpa = :gpa,
                email = :email,
                    filename = :filename,
                    mimetype = :mimetype,
                    filedata = :filedata
                WHERE id = :id";
            $s = $pdo->prepare($sql);
            $s->bindValue(':id', $_POST['id']);
            $s->bindValue(':name', $_POST['name']);
            $s->bindValue(':age', $_POST['age']);
            $s->bindValue(':position', $_POST['position']);
            $s->bindValue(':height', $_POST['height']);
            $s->bindValue(':weight', $_POST['weight']);
            $s->bindValue(':satscore', $_POST['satscore']);
            $s->bindValue(':gpa', $_POST['gpa']);
            $s->bindValue(':email', $_POST['email']);
                    $s->bindValue(':filename',  $uploadname);
                    $s->bindValue(':mimetype',   $uploadtype);
                    $s->bindValue(':filedata',   $uploaddata);
            $s->execute();
        }
        catch (PDOException $e)
        {
            $error = 'Error editing player profile main details.' . $e->getMessage();
            include 'error.html.php';
            exit();
        }

I thought I could do something like this but it is not working:

if (isset($_FILES['upload']) && $_FILES['upload'] <> '') 
{
$s->bindValue(':filename',  $uploadname);
$s->bindValue(':mimetype',   $uploadtype);
$s->bindValue(':filedata',   $uploaddata);
}
else
{
$s->bindValue(':filename',  $filename);
$s->bindValue(':mimetype',   $mimetype);
$s->bindValue(':filedata',   $filedata); 
}

All help is appreciated.

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-06-10T15:44:42+00:00Added an answer on June 10, 2026 at 3:44 pm

    main algo to your code

    if (isset($_POST['action']) and $_POST['action'] == 'Edit')
    { 
    
        if (!empty($_FILES) and is_uploaded_file($_FILES['upload']['tmp_name'])) {
           $sql = "UPDATE player SET
                    name = :name,
                    age = :age,
                    position = :position,
                    height = :height,
                    weight = :weight,
                    satscore = :satscore,
                    gpa = :gpa,
                    email = :email,
                        filename = :filename,
                        mimetype = :mimetype,
                        filedata = :filedata
                    WHERE id = :id";
        } else {
            $sql = "UPDATE player SET
                    name = :name,
                    age = :age,
                    position = :position,
                    height = :height,
                    weight = :weight,
                    satscore = :satscore,
                    gpa = :gpa,
                    email = :email
                    WHERE id = :id";
        }
    
        try {
            //skipped
    
            if (!empty($_FILES) and is_uploaded_file($_FILES['upload']['tmp_name'])) {
                $s->bindValue(':filename',  $uploadname);
                $s->bindValue(':mimetype',   $uploadtype);
                $s->bindValue(':filedata',   $uploaddata);
            }
    
        } catch(PDOException $e) {
            //skipped
        }
    }
    

    http://www.php.net/manual/en/function.is-uploaded-file.php

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

Sidebar

Related Questions

I have a strange problem with my code. i'm trying to create a form
I'm trying to edit the httpd.conf file located in /private/etc/apache2, and I can't figure
I'm trying to create a social network and I'm having a problem with my
I'm trying to make a simple sudoku but I have a problem with the
I am trying to set up Eclipse so I can profile a Java program
I have a form where users get edit their personal information/settings and I'm trying
When trying Edit Table Data in MySQL Workbench 5.2.37, its in read only mode.
I'm trying to edit this submit tag to make it disable itself once I
I'm trying to edit a form with a ImageField and I´m using modelformset_factory in
I am trying to edit the sidebar of a mediawiki page by making a

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.