Once you’ve added or edited a database table, it’s good to check that the change/addition was made… then either move on or show an error, etc.
Here’s how to do it with mysql_affected_rows().
Note, if the same data was submitted, i.e. a form with values filled in from the database was submitted without the values being changed, then the ‘affected row count’ is likely to be ‘zero’, so you might trigger an error, when infact there’s no error, just nothing was requested to change
if(mysql_affected_rows() !=0){ // if the affected row count is not 'zero' // Do something like reload page, print a success message } else { // if nothing has happened // create error or check that the user actually asked something to change.
Main Category
Secondary Categories