Blank screen when Saving to DB

Hi guys! I am having trouble with editing data from my DB via this form.

I used “add to DB form” that works perfectly fine to make an edit form but as soon as I submit it in the broswer it takes me to blank screen, and there are no changes into DB.

Glad if you can help me sort it out since it took much time already.

Hope codepile is ok to share my code here.

https://www.codepile.net/pile/0maqgWmx

Turn error reporting on by put this on top of your page or in a configuration file ->

error_reporting(-1); // -1 = on || 0 = off

1 Like

The most immediate problem is an error in one of the sql queries. You are actually fortunate that an update query isn’t being executed, because it would mess up the saved hashed passwords (do NOT retrieve the hashed password values from the database and output them as a form field value.)

Instead of using out of date or die(…) statements for error handling, use exceptions for database statement errors and in most cases let php catch and handle the exception where it will use its error related settings to control what happens with the actual error information (database errors will get displayed/logged the same as php errors.) The exception to this rule is when inserting/updating user submitted data and you need to handle duplicate or out of range values. In this case, your code would catch the exception, detect if the query error number is one that your code can handle and recover from, and set up a message telling the user what exactly was wrong with the submitted data. If the error number is not one that your code is designed to handle, you would re-throw the exception and let php handle it. Detecting duplicate user submitted data is something you need to do, but first get your code to work without this feature.

To enable exceptions for errors for the mysqli extension, add the following single line of code before the point where you make the database connection, then remove all the database error handling logic you have now -

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

Next, there are issues with almost everything this code is doing, that are either non-secure, unnecessary, wasteful, or provide a bad user experience. If I/others have time we will post list(s) of problems and good programming practices to use…

1 Like

Thank you for all the tips and help.That was exactly what I needed to solve this problem. :slight_smile:
Hopefully it’s just an excersise project but you helped me put it on another level. Thanks again!

Sponsor our Newsletter | Privacy Policy | Terms of Service