Shadow Wolf Posted March 7, 2006 Share Posted March 7, 2006 I am making a 3 column website. The left/right column are static through-out the site and the center column is the main column that changes. To make it easier I created it in php and then use a php include for the center part. I would like to make a Accept and Do Not Accept link/button that they can select and it would then show the rest of the page. I know how to make it so I can do accept/not accept and then it would redirect it. However I would like it to instead just include the file if they click yes, but redirect if they say no.[code]<?if ($YES) {include("test.htm");} else {$URL="http://www.example.com";header ("Location: $URL");}?> [/code]I believe something like that would work (probably some syntax wrong somewhere). Where do I put in the $YES choice, something like Accept and I Do Not Accept part.Can someone help me out? Am I on the right track? Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/ Share on other sites More sharing options...
php_b34st Posted March 7, 2006 Share Posted March 7, 2006 Yes you are on the right track for processing the asccept/do not accept. Is it the actual accept/do not accept part that posts the to $yes that you want help with? if so are you wanting to do it as a form where you have submit buttons or use hyperlinks? Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-15183 Share on other sites More sharing options...
Shadow Wolf Posted March 8, 2006 Author Share Posted March 8, 2006 Yes I am for some reason having a complete brain-ism and can't seem to figure out how to properly set it up. Hyperlinks or buttons would work, doesn't really matter to me. I could simply put Yes and No in a hyperlink and basic HTML, but not sure how to write it so it translate the click on the link as Yes or No. Maybe using a form to have a submit and no button or something. Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-15508 Share on other sites More sharing options...
lessthanthree Posted March 8, 2006 Share Posted March 8, 2006 if you want to use a hyperlink you can use something like.[code]<a href='index.php?continue=1'>Yes</a><a href='index.php?continue=0'>No</a>//then where you want to check what happened:if (isset($_GET["continue"]){ if ($_GET["continue"] == 1) require_once("page.php"); else //do something else}[/code]example of way to do it with a form[code]<form name='foo' method='post'> <select name='bar'> <option value='1'>Yes</option> <option value='0'>No</option> </select> <input type='submit'></form>if (isset($_POST["submit"])){ if ($_POST["bar"] == 1) require_once("page.php"); else //do something else}[/code]hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-15566 Share on other sites More sharing options...
Shadow Wolf Posted March 14, 2006 Author Share Posted March 14, 2006 The syntax seems wrong but I should be able to correct it to get to work. If I do it that way though, will it work like a php include would? Or would it just redirect it to that page?I am using an include because it pulls the main page and then places it basically within the cell it is supposed to go. If it just redirects then it would break out of the format for the website. Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-17414 Share on other sites More sharing options...
Shadow Wolf Posted March 15, 2006 Author Share Posted March 15, 2006 I have tried to do this but still can't get it to work. I have tried both:[code]<?<a href="index.php?continue=1">Yes</a><a href="index.php?continue=0">No</a>if (isset($_GET["continue"]){ if ($_GET["continue"] == 1) require_once("page.php");} else {echo "test";}?>[/code]and[code]<form name="foo" method="post"> <select name="bar"> <option value="1">Yes</option> <option value="0">No</option> </select> <input type="submit"></form><?if (isset($_POST["submit"])){ if ($_POST["bar"] == 1) require_once("page.php"); } else {echo "You have selected No";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-17932 Share on other sites More sharing options...
XenoPhage Posted March 15, 2006 Share Posted March 15, 2006 What output are you getting? Are you getting errors? Have you included that page anywhere else in the script? Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-17936 Share on other sites More sharing options...
Shadow Wolf Posted March 18, 2006 Author Share Posted March 18, 2006 When I use this:[code]<form name="foo" method="post"> <select name="bar"> <option value="1">Yes</option> <option value="0">No</option> </select> <input type="submit"></form><?if (isset($_POST["submit"])){ if ($_POST["bar"] == 1) require_once("page.php"); } else {echo "You have selected No";}?>[/code]I receive no errors. What do you mean have I included it anywhere else in the script? The only thing I have been using was what is above, that is it. Should it have been combined with something?It loads page agree.php which has the code, there is drop down menu with yes and no. Selecting yes doesn't take it to page.php. It automatically echoes the selected No, when I only want it to do or say that action if they select no.[a href=\"http://www.pcxdesigns.com/temp/agree.php\" target=\"_blank\"]Test Example[/a] Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-18609 Share on other sites More sharing options...
theverychap Posted March 18, 2006 Share Posted March 18, 2006 [code]<?php// form is submittedif ( isset($_POST['submit']) ){ $agree = $_POST['agree']; if ( $agree == 'yes' ) { header('location: page.php'); } else if ( $agree == 'no' ) { echo 'you have selected no<br/>'; } else { echo 'form not submitted yet<br/>'; show_form(); }}function show_form();{ ?> <form name="question" action="" method="post"> <select name="agree"> <option value="yes">Yes</option> <option value="no">No</option> </select> <input type="submit" name="submit" value="continue" /> </form> <?php}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-18646 Share on other sites More sharing options...
Shadow Wolf Posted March 18, 2006 Author Share Posted March 18, 2006 Thank you for the help.I receive the following error now:[code]Parse error: parse error, unexpected ';', expecting '{' in /home/protocul/public_html/temp/agree.php on line 25[/code]Line 25:[code]function show_form();[/code]If I removed the ; in line 25, I don't receive an error anymore but when I load the page it is a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-18648 Share on other sites More sharing options...
Shadow Wolf Posted March 22, 2006 Author Share Posted March 22, 2006 Anyone have any ideas on this? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-19770 Share on other sites More sharing options...
Shadow Wolf Posted March 30, 2006 Author Share Posted March 30, 2006 I am probably not understanding it fully because I kept receiving a blank white screen. So I went back to the guides and tutorials and started from scratch again, creating my test file called form.php. I think I found out what happened. I was able to get it to work in my test. It would load the page, show the question and have a yes and no option. If I selected no it just said you have selected no. If I selected yes, it would then include xxx.htm file. The problem was that it remembers what it did. So if I try to back to the form.php URL it would automatically include the xxx.htm file because that was what was chosen before. If I chose no then it would say I chose no. It isn't giving me the option each time I go to the form URL, it just remembers my last choice.Example:[a href=\"http://www.pcxdesigns.com/temp/form.php\" target=\"_blank\"]http://www.pcxdesigns.com/temp/form.php[/a][code]<?php// form is submittedif ( isset($_POST['submit']) ){ $agree = $_POST['agree']; if ( $agree == 'yes' ) {include 'index2.htm'; } else if ( $agree == 'no' ) { echo 'you have selected no<br/>'; }}?>Thank you for your interest. Do you agree to blah blah blah test.<form name="question" method="post"><select name="agree"> <option value="yes">Yes</option> <option value="no">No</option></select><input type="submit" name="submit" value="continue" /></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/4360-using-php-include-and-if/#findComment-22339 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.