Preserve Form POST Data Displaying Errors

Preserve Form POST Data Displaying Errors

I have a form that displays a group of drop-down lists using data from my MySQLi database for updating. My program edits the data and displays an error message for incorrect data. The program displays the error messages correctly. However, it displays the old data from the database rather than the incorrect data the user entered. I use your recordset code to query the database. However, I'm currently updating the database with my own SQL code and will use your update behavior once I solve this problem. My PHP code is attached. I can't believe how much time I've lost on this!

You would have to create the recordset after the update if you wanted it to have the updated values. Just move the code that updates the database above the recordset code or more the recordset below the update and I think it will give you the result you are looking for.

Preserve Form POST Data Displaying Errors

Originally Said By: Ray Borduin

You would have to create the recordset after the update if you wanted it to have the updated values. Just move the code that updates the database above the recordset code or more the recordset below the update and I think it will give you the result you are looking for.

That didn't work. I only update the database if there are not any errors from my validations. It seems like what you're saying is update the database with incorrect data, them display it. I'm confused! I've attached my updated code with your suggestion of putting the update code BEFORE the recordset.

I see... you would probably have to save the entered values into session variables when validation fails so that you could repopulate the form with the previous values when they return to the page. Set the values to the session variables if they exist or use the defaults if they don't.

If you were using webassist validations from DataBridge this would be done for you by the validation scripts.

Ray, I used a variation of your suggestion and it worked! I wrapped an if statement around my drop-down lists. If !isset($_POST[field]) display data from the database OR if isset($_POST[field]) display POST data. As usual, thanks so much for your superb assistance. I checked out DataBridge and will most definitely consider it.