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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:51:44+00:00 2026-06-14T10:51:44+00:00

I am working on a PHP web application that allows the user to edit

  • 0

I am working on a PHP web application that allows the user to edit values grabbed from a database. The user clicks an ‘edit’ link, and the fields are populated with the data from the table in the database (if there is any). If there isn’t any data, all of the fields just show up blank.

When the user clicks ‘save’, the form is submitted to POST, and those values are saved to the database with an “UPDATE” query.

I check the result of the query by checking for the “affected rows”. If it’s equal to 0, then the changes didn’t go through and I tell the user.

However, I have a slight problem when the user updates with the exact same values that the row already contains.

For example,
A row I have with columns, A, B, C, D which have the values 1, 2, 3, 4 respectively.

If the user edits that row, and submits with values 1, 2, 3, 4, the row will not be affected and my output message will say that the query failed when the “updates” are really the same as before and went through just fine.

Right now I’m stuck with outputting:

“The updated values are the same as the old ones OR there is something wrong with the tables and column names. Check the logs.”

I send a message to the logs regarding this error. I then output the query just so the user can see.

The thing is, I want my program to be informative when it comes to errors. Is there a way to have the program classify an update that is the exact same as what the row originally was as.. successful?

        // construct query, execute query, check if any rows have been affected
    $query = "UPDATE table SET status='$status', client='$client' WHERE key='$key'";
    $result = $conn->query($query);
    if(mysqli_affected_rows($conn) === 0)
    {
        echo "Something went wrong. Entry not updated. Check the logs.\n";
        echo $query;
        error_log(mysqli_error($conn));
    }

I’ve also thought about just checking if $result === false or $result === true inside the if condition, but would that work?

Any insight is greatly 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-14T10:51:45+00:00Added an answer on June 14, 2026 at 10:51 am

    If you want to check for an error with your query, you can check for -1 instead of 0.

    If mysqli_affected_rows returns 0 it means that nothing was updated because of no changed values or no matching WHERE condition. If you need to distinguish between these two, you would probably need to do an additional SELECT query.

    And you need to use prepared statements with bound variables to avoid sql injection problems.

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

Sidebar

Related Questions

I am working on web application that will use PHP & MySQL. Application will
Recently I am working into the ability of translating a PHP web application from
I'm working on a web application that need to allow the user to drag
I am working on a web application that uses PHP and JavaScript and I
I am developing a web application that allows a user to add entries to
I am working on a web application(using PHP) which will use MySQL database in
I'm developing a PHP web application that is heavy on the database interactions. My
I am currently working on a web application that uses PHP and MySQL, but
I'm working on an old php web application. The problem is the organization of
I am working on a PHP sandbox for a Web Application Honeypot. The PHP

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.