Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

!IsSet with $_POST

Status
Not open for further replies.

CliffLandin

Programmer
Nov 14, 2004
81
US
The problem with the code in the first place is that should $_POST['user'] not exist, the script will generate a warning at the statement:

$userName = $_POST["user"];

I would recommend doing all the tests against $_POST['user'], etc.


Using the following 3 HTML files:

test_redir0.html:
Code:
<html><body>
<form method="post" action="/test_redir1.php">
<input type="submit">
</form></body></html>

test_redir1.html:
Code:
<html><body>
<form method="post" action="/test_redir1.php">
<input type="text" name="user"><br>
<input type="submit">
</form></body></html>

test_redir2.html:
Code:
<html><body>
<form method="post" action="/test_redir1.php">
<input type="text" name="user"><br>
<input type="text" name="pWord"><br>
<input type="submit">
</form></body></html>

And the following two scripts:
test_redir1.php:
Code:
<?php
if (!isset($_POST["user"]))
	header("Location: /test_redir2.php?error=1");
elseif (!isset($_POST["pWord"]))
	header("Location: /test_redir2.php?error=2");
	
print '<html><body>got all</body></html>';
?>

test_redir2.php:
Code:
<?php
print '<html><body>';
print 'first<br><pre>';
print_r ($_GET);
print '</pre></body></html>';
?>

Everything works as I expect. If I open test_redir0.html and submit, my browser eventually ends up at test_redir2.php and $_GET contains "[error] => 1". If I open test_redir1.html and submit, my browser ends up at test_redir2.php, and $_GET has "[error] => 2". If open test_redir2.html and submit, my browser stays at rest_redir1.php and the page reads "got all".







Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top