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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:49:03+00:00 2026-05-14T06:49:03+00:00

When I submit a new name and not a new avatar I get the

  • 0

When I submit a new name and not a new avatar I get the following avatar error message Please upload a .gif, .jpeg, .jpg or .png image!. I want to be able to send a new name only without having to upload a new avatar each time I submit the form without getting the avatar error message Please upload a .gif, .jpeg, .jpg or .png image! can someone help me fix this problem?

Here is the php code.

if (isset($_POST['submitted'])) {

    $mysqli = mysqli_connect("localhost", "root", "", "sitename");
    $dbc = mysqli_query($mysqli,"SELECT users.*
                                 FROM users 
                                 WHERE user_id=3");

    $first_name = mysqli_real_escape_string($mysqli, htmlentities(strip_tags($_POST['first_name'])));

$user_id = '3';

if(isset($_FILES["avatar"]["name"]) && $_FILES['avatar']['size'] <= 5242880) {

    if($_FILES["avatar"]["type"] == "image/gif" || $_FILES["avatar"]["type"] == "image/jpeg" || $_FILES["avatar"]["type"] == "image/jpg" || $_FILES["avatar"]["type"] == "image/png" || $_FILES["avatar"]["type"] == "image/pjpeg") {

        if (file_exists("../members/" . $user_id . "/images/" . $_FILES["avatar"]["name"])) {
          echo '<p class="error">' . mysqli_real_escape_string($mysqli, htmlentities(strip_tags(basename($_FILES["avatar"]["name"])))) . ' already exists! ';
        } else if($_FILES["avatar"]["name"] == TRUE) {
          move_uploaded_file($_FILES["avatar"]["tmp_name"],
          "../members/" . $user_id . "/images/" . mysqli_real_escape_string($mysqli, htmlentities(strip_tags(basename($_FILES["avatar"]["name"])))));
          $avatar = mysqli_real_escape_string($mysqli, htmlentities(strip_tags(basename($_FILES["avatar"]["name"]))));
        }

    } else if($_FILES["avatar"]["type"] != "image/gif" || $_FILES["avatar"]["type"] != "image/jpeg" || $_FILES["avatar"]["type"] != "image/jpg" || $_FILES["avatar"]["type"] != "image/png" || $_FILES["avatar"]["type"] != "image/pjpeg") {
        echo '<p class="error">Please upload a .gif, .jpeg, .jpg or .png image!</p>';
    }

} else if($_FILES['avatar']['size'] >= 5242880) {
    echo '<p class="error">Please upload a smaller pic!</p>';
} else if($_FILES["avatar"]["name"] == NULL) {
    $avatar = NULL;
}


if(isset($_FILES["avatar"]["name"]) && $_FILES['avatar']['size'] <= 5242880) {

        if (mysqli_num_rows($dbc) == 0) {
                $mysqli = mysqli_connect("localhost", "root", "", "sitename");
                $dbc = mysqli_query($mysqli,"INSERT INTO users (user_id, first_name, avatar) 
                                             VALUES ('$user_id', '$first_name', '$avatar')");
        }

        if ($dbc == TRUE) {
                $dbc = mysqli_query($mysqli,"UPDATE users 
                                             SET first_name = '$first_name', avatar = '$avatar' 
                                             WHERE user_id = '$user_id'");

                echo '<p class="changes-saved">Your changes have been saved!</p>';

        }

        if (!$dbc) {
                print mysqli_error($mysqli);
                return;
        }

    }

}
  • 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-14T06:49:04+00:00Added an answer on May 14, 2026 at 6:49 am

    You simply need to add a check to see if they specified a new image for their avatar (or left it blank). In that case, without knowing how your form is set up, you could simply check that the size is greater than zero (isset()/empty() can return unexpected results in this case):

    if($_FILES['avatar']['size'] > 0) { ... }
    

    Edit
    In response to your comment, you’d change the following line (including fixing a basic logic error):

    } else if($_FILES["avatar"]["type"] != "image/gif" || $_FILES["avatar"]["type"] != "image/jpeg" || $_FILES["avatar"]["type"] != "image/jpg" || $_FILES["avatar"]["type"] != "image/png" || $_FILES["avatar"]["type"] != "image/pjpeg") {
    

    to:

    } else if($_FILES["avatar"]["size"] <= 0 && $_FILES["avatar"]["type"] != "image/gif" && $_FILES["avatar"]["type"] != "image/jpeg" && $_FILES["avatar"]["type"] != "image/jpg" && $_FILES["avatar"]["type"] != "image/png" && $_FILES["avatar"]["type"] != "image/pjpeg") {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.