If-Then Go To Page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

If-Then Go To Page?

Post 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]
MinDFreeZ
Forum Commoner
Posts: 58
Joined: Tue Feb 14, 2006 12:28 pm
Location: Lake Mary, FL

Post 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
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

wow. thanks.
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post 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?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

(remember to always always use full url's in header redirections.)
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

(what browsers depend on that anymore?)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post 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)
MinDFreeZ
Forum Commoner
Posts: 58
Joined: Tue Feb 14, 2006 12:28 pm
Location: Lake Mary, FL

Post by MinDFreeZ »

can u show the full current code?
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post 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.
Post Reply