I created a form and when I submit the form, my php writes the form data to a database. Done.
But now I am seeing that the form is still written to the database when some fields are left blank, the code just writes variables left over from the last submission that had the form field filled out.
I have tried the following if statement but this is not cutting it:
if ( isset( $_POST['request_num']) ) {
// write to the database
}
Can I modify the if-statement to say: run the code IF the variable $_POST['request_num']
has been set on this submission and ignore all old value set by previous submissions?
You can try this:
if (!empty( $_POST['request_num'])) {
// write to the database
header('Location: index.php');
}
Using the header will ensure that you won't refresh from the browser and resend the form data. Replace index.php with the proper file name.