rendrik Posted March 10, 2006 Share Posted March 10, 2006 I'm having this issue with form validation..Basically it just skips all my if statements such as:[code]if(!$_POST["first_name"] || !$_POST["last_name"] || !$_POST["email"] || !$_POST["mailing_street"] || !$_POST["mailing_city"] || !$_POST["mailing_state"] || !$_POST["mailing_zip"]) header("location: profile.php?reason=info"); if($password1 != $password2) header("location: profile.php?reason=password");if(check_email_address($emailaddress) == false) header("location: profile.php?reason=email"); if($mailingstate == "XX") header("location: profile.php?reason=info"); [/code]And goes right to the database portion where it dutifully updates the person's record with any gibberish they put in.Interestingly enough, if I put a die("dead"); anywhere in the code, the if statements magically work. I'm thinking there is some kind of syntax error i'm just not seeing, is there anything I should be looking for? This has had me stumped for awhile. Link to comment https://forums.phpfreaks.com/topic/4577-if-statement-issue/ Share on other sites More sharing options...
php_b34st Posted March 10, 2006 Share Posted March 10, 2006 You need to put if statements within {} try:[code]if(!$_POST["first_name"] || !$_POST["last_name"] || !$_POST["email"] || !$_POST["mailing_street"] || !$_POST["mailing_city"] || !$_POST["mailing_state"] || !$_POST["mailing_zip"]){ header("location: profile.php?reason=info");}if($password1 != $password2){ header("location: profile.php?reason=password");}if(check_email_address($emailaddress) == false){ header("location: profile.php?reason=email");}if($mailingstate == "XX"){ header("location: profile.php?reason=info");}[/code] Link to comment https://forums.phpfreaks.com/topic/4577-if-statement-issue/#findComment-15997 Share on other sites More sharing options...
AV1611 Posted March 10, 2006 Share Posted March 10, 2006 Here it is from the opposite direction... Lemme know...[code]if(isset($_POST["first_name"]) && isset($_POST["last_name"]) && isset($_POST["email"]) && isset($_POST["mailing_street"]) && isset($_POST["mailing_city"]) && isset($_POST["mailing_state"]) && isset($_POST["mailing_zip"])){ if($password1 !== $password2) header("location: profile.php?reason=password"); if(check_email_address($emailaddress) == false) header("location: profile.php?reason=email"); if($mailingstate == "XX") header("location: profile.php?reason=info"); }else {header("location: profile.php?reason=info");} [/code] Link to comment https://forums.phpfreaks.com/topic/4577-if-statement-issue/#findComment-15998 Share on other sites More sharing options...
kenrbnsn Posted March 10, 2006 Share Posted March 10, 2006 Instead of multiple "if" statements, you could try using a "switch" statement:[code]<?phpforeach ($_POST as $k => $v) switch ($k) { case 'first_name': // here are all the fields that can't be blank case 'last_name': case 'mailing_street': case 'mailing_city': case 'mailing_zip': if (strip_tags(trim($v)) == '') header('location: profile.php?reason=info'); break; case 'password1': if ($v != $_POST['password2']) header('location: profile.php?reason=password'); break; case 'email': if (strip_tags(trim($v)) == '') header('location: profile.php?reason=info'); if (!check_email_address($v)) header('location: profile.php?reason=email'); break; case 'mailing_state': if (strip_tags(trim($v)) == '' || $v == 'XX') header('location: profile.php?reason=info'); break; }?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/4577-if-statement-issue/#findComment-16003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.