PHP (any version) doesn't enter any information on its own... it does exactly what you tell it to do.
Originally Posted by David P
Checking a single entry like say (cat) is easy, but checking to see if the contents of a POSTed textarea is identical to what is in the mysql field is not.
Who said you had to check what was in the database? You already know what was in the database when you first generated that form, so you could either a) store that data in a session, or b) store that data in hidden form elements or in cookies. If you get a submission where the POST'ed data matches the data you previously used to generate the update page, then you know that the user didn't change anything - thus, there's no reason to even bother connecting to your DB, let alone trying to query it in any way.
But again, you could accomplish this quite easily on the client side of things using Javascript, meaning you could save even more resources by not allowing the form to be submitted in the first place.
Originally Posted by David P
PHP Code:
if ($r === $_SESSION['duty']) { // also tried ($r == $_SESSION['duty'])
Neither one of those comparisons makes any sense; mysqli_query() is going to (hopefully) return a resource, yet you're trying to compare it to a string (POST'ed data).
Originally Posted by David P
If the purpose of PHP 5 not re-entering in the same data in an update is to save time and resources, but you have to perform an additional query to test the MySQL data against the posted variable data, then what have you gained?
Not much (i.e. probably nothing), which is why I never suggested doing that.
I just changed and tested my script and I have it working. I was pulling the information out of the database to compare it to the posted variable instead of testing for identical content in the query.
PHP Code:
$q = "SELECT * FROM duties WHERE duty_id='$duty_id' AND duty='".$_SESSION['duty']."'";
This works and satisfies my immediate need, but as some suggested, checking for any change of content prior to the query also makes sense so I'll experiment with that some.
I don't seem to recall earlier versions of PHP or MySQL throwing errors when attempting to update the database with the same information. Maybe it did and I didn't notice, although it it wasn't working I'm sure someone would have notified me. Hmmm. This is why I thought that this was new behavior.
I just got my book in on PHP 5 and MySQL 5 and have began updating my pages with the mysqli. I'll use the procedural method since it's closer to what I'm used to. I've also started reading about JavaScript and I can see where it could certainly be very beneficial at times.
Anyway, thanks for all the help on this. I know that teaching can be very frustrating at times, but I appreciate your willingness to do it. I'm not immediately sure as to how to mark this topic resolved but I'll look into that more after I make this post.
I don't seem to recall earlier versions of PHP or MySQL throwing errors when attempting to update the database with the same information. Maybe it did and I didn't notice, although it it wasn't working I'm sure someone would have notified me. Hmmm. This is why I thought that this was new behavior.
And it's not throwing errors now. Your code is saying that there is an error.
Bookmarks