nblackwood Posted May 17, 2010 Share Posted May 17, 2010 Hey everyone. I have this code that I put together which is intended to check if the user has selected an answer within the survey. I know how to check if a session or post variable is empty or not. The issue is that the I am unable to use "else" before the "die()" function, and also, the error is echoed on the page . My question is, how do I validate the session, and only display the error message in a certain place on the page without killing the entire script after that point? The script I am using for my validation logic is: <?php session_start(); $gender = $_POST['gender']; $_SESSION['gender']=$gender; if (empty($_SESSION['gender'])) die; echo 'Selection cannot be empty'; else require_once('page2.php'); ?> Link to comment https://forums.phpfreaks.com/topic/201992-session-validation-logic/ Share on other sites More sharing options...
Pikachu2000 Posted May 17, 2010 Share Posted May 17, 2010 That script isn't giving you a parse error? It should. Why not validate the form field before trying to set the session var? If you don't want to kill the script, don't tell it to die(). if (empty($_POST['gender'])) { echo 'Selection cannot be empty'; } else { $_SESSION['gender'] = $_POST['gender']; } Link to comment https://forums.phpfreaks.com/topic/201992-session-validation-logic/#findComment-1059333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.