Page 1 of 1

If-Then Go To Page?

Posted: Wed Feb 22, 2006 9:53 am
by steves
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I'm not a developer, just taught myself a little php to extract info from a MySQL database.  So, not evene really "newbie", more of "novice hack."

What I want to do now is use an HTML form with a select (drop-down), and use the resulting variable to select a new page to go to.  I'm giving the user 3 options.  So, basically, the php code so far looks like:

Code: Select all

<?php
	if (isset($_GET['action']) && $_GET['action'] == 'submitted') {

		if ($_GET['router'] == 'enterInfo') {
			$page_to = 'edititem3.php' ;		
			}
		elseif ($_GET['router'] == 'reviewData') {
			$page_to = 'reviewData.php' ;
			}
		elseif ($_GET['router'] == 'selectPrint') {
			$page_to = 'goPrint.php' ;
			}
		}
		} else {
	?>
	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
		<input name="router" type="radio" value="enterInfo">Enter New INFO<br>
		<input name="router" type="radio" value="reviewData">Review Existing Info<br>
		<input name="router" type="radio" value="selectPrint">Select & Print Reports<br>

		<input type="hidden" name="action" value="submitted" />
		<input type="submit" name="submit" value="Go Do It" />
	</form>
My question is: is there a way to use "$page_to" to actually select and go to a new page? The pages would be significantly different depending on the value of "$page_to", so a php?page_to= would be really ugly, I think.

Thanks.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Wed Feb 22, 2006 10:02 am
by MinDFreeZ
if ($_GET['router'] == 'enterInfo') {
$page_to = 'edititem3.php' ;
header("Location: http://www.example.com/");
}

don't know if thats what you mean..
maybe even.. header("Location: index.php?action=edititem3.php");
i dont know if that crap works :P

Posted: Wed Feb 22, 2006 10:09 am
by steves
wow. thanks.

Posted: Wed Feb 22, 2006 10:17 am
by steves
Oh, one more thing. with this method, can I pass a variable from this page to the page I'm going to? For example, if I have another <select> variable in the form for "Employee Name", can I then pass that variable to either of the three pages that are selected by the if statement?

Posted: Wed Feb 22, 2006 10:22 am
by shiznatix
nope, cant do it. ahha, i got you, you really can do it! woooooo oh man....

just do like this:

Code: Select all

if ($_GET['router'] == 'enterInfo')
{
            $page_to = 'edititem3.php?employee='.$_GET['employee'] ;
    header("Location: $page_to");
}
then on the edititem3.php just use the variable $_GET['employee'] and you will be golden.

Posted: Wed Feb 22, 2006 10:25 am
by s.dot
shiznatix wrote:nope, cant do it. ahha, i got you, you really can do it! woooooo oh man....
:lol: best thing i've read today.

Posted: Wed Feb 22, 2006 10:30 am
by feyd
(remember to always always use full url's in header redirections.)

Posted: Wed Feb 22, 2006 10:37 am
by shiznatix
(what browsers depend on that anymore?)

Posted: Wed Feb 22, 2006 10:44 am
by feyd
All of them. If you want to follow the HTTP standards -- why wouldn't you? -- a full URL is required 100% of the time in a header redirection.

Posted: Wed Feb 22, 2006 10:48 am
by steves
shiznatix:

thanks. not working, but it makes sense. i'll read up from here, unless you have a quick idea why it breaks.

(on edititem3.php, i entered

Code: Select all

$employee=$_GET['employee']
and then called $employee; got a NULL value. BTW, employee=John%20W.%20Doe does appear in the URL)

Posted: Wed Feb 22, 2006 11:11 am
by MinDFreeZ
can u show the full current code?

Posted: Wed Feb 22, 2006 11:19 am
by steves
I figured out the problem. The $_GET was embedded in an IF statement.

I do have other problems, tho. I'm sure I'll be posting one or two... Thx.