PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Alright im very new to php and I was wondering how to make sure people fill out a form before they submit it. If they were to forget to fill something out i would like it let them know what they forgot and try again. I'm doing this off of two files, my index and a process.php file. I will put what code i have below, i believe i have everything except for the code that would check to see if it is filled out. Any help is appreciated
if (strlen(trim($_POST['fname'])) == 0) {
header("Location:index.php?err=user");
}
if (strlen(trim($_POST['movie'])) == 0) {
header("Location:index.php?err=pw");
}
That would be the easiest way to plug into what you already have written. I would recommend using the same form field/variable names across the board for simplicity purposes.
Personally, I would array all of the form elements, and then parse through the array. Makes it easier to make changes in the future too.
thanks a ton, that worked like a charm, the only thing is it still saves it to the database even though the message telling them that they forgot a text field does come up. any knowledge on how to stop it from saving the data if its not completed.
That's strange. Modifying header location should kick the user over instantly and not process any more code (I think?).....unless you have something displaying on the page before the call (will throw "headers already sent" error). Try adding ob_start(); to the first line of the processing page.