twilitegxa Posted September 23, 2008 Share Posted September 23, 2008 I have a page that users will select by radio button if they want to create a male or female character, then also a hero or villain. I want to know how to write the script that would direct them to a specific page the following conditions are met: If female and hero ---> scout.php If male and hero ---> knight.php If villain, male or female ---> villain.php Right now I have it set as a form, but I'm not sure how to direct the action properly or what type of code to use. Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/125420-solved-directing-to-page-on-submit-if-condition-is-met/ Share on other sites More sharing options...
JasonLewis Posted September 23, 2008 Share Posted September 23, 2008 Well you would get the values after the form as been submitted, then run an if statement. $gender = $_POST['gender']; //Male or female? $status = $_POST['status']; //Hero or villain? if($status == "villain"){ //Since you're a villain, we just redirect here to the villain page }elseif($status == "hero"){ if($gender == "male"){ //You are a male hero! }elseif($gender == "female"){ //You are a female hero! } } Quote Link to comment https://forums.phpfreaks.com/topic/125420-solved-directing-to-page-on-submit-if-condition-is-met/#findComment-648440 Share on other sites More sharing options...
twilitegxa Posted September 23, 2008 Author Share Posted September 23, 2008 How do I put the code in your example to send them to the appropriate page? Sorry, I'm still pretty new to PHP coding. :-) Quote Link to comment https://forums.phpfreaks.com/topic/125420-solved-directing-to-page-on-submit-if-condition-is-met/#findComment-648443 Share on other sites More sharing options...
twilitegxa Posted September 23, 2008 Author Share Posted September 23, 2008 I got it. I can use the header within the code like this: <?php $gender = $_POST['gender']; //Male or female? $status = $_POST['status']; //Hero or villain? if($status == "villain"){ //Since you're a villain, we just redirect here to the villain page header("Location: villain.php"); exit; }elseif($status == "hero"){ if($gender == "male"){ //You are a male hero! header("Location: knight.php"); exit; }elseif($gender == "female"){ //You are a female hero! header("Location: scout.php"); exit; } } ?> Thanks for the help!!! Quote Link to comment https://forums.phpfreaks.com/topic/125420-solved-directing-to-page-on-submit-if-condition-is-met/#findComment-648451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.