Hi, Thursday, March 4, 2004, 8:11:16 PM, you wrote: mo> Thanks for your reply,
mo> I am still a bit confused though as the var error is never set! i.e. in your mo> code example below $error is never going to be set! Basically I have 2 pages mo> as follows: mo> page1.php - login form page mo> page2.php - validation page mo> page2.php checks the usernae and password against database and if all is mo> well it sends to the members area. If there was an error then it sends back mo> to the login page. When there is an error on page2.php I want to set a mo> request variabel called "$someError" with a value representing the error mo> that occured i.e. "Please enter a username" or "Please enter a password" or mo> "Invalid username" or "invalid password" etc.. Then on page1.php just before mo> the login form I would do: mo> if (!empty($_POST('someError'))) { mo> echo $_POST('someError'); mo> } mo> //display login form. mo> So my question is how do I add the variable $someError to the request with mo> the value "invalid usernam" and disaply this on page1.php mo> $error = ''; //assume no errors mo> if(isset($_PHP['password'] && !empty($_POST['username']){ mo> $sql = "SELECT id FROM members WHERE mo> username = '".$_POST['username']."' mo> AND password = '".$_POST['password']."'"; mo> $result = mysql_query($sql); mo> if(!$mysql_num_rows($result) > 0){ mo> $error = '<font color="red"><b>Error:</b> Invalid password</font>'; mo> include('login.php'); mo> exit; mo> } mo> //password ok mo> echo 'Welcome '.$_POST['username'].'<br>'; mo> }else{ mo> //first pass and $error is still empty mo> include('login.php'); mo> } mo> ----- Original Message ----- mo> From: "Tom Rogers" <[EMAIL PROTECTED]> mo> To: "matthew oatham" <[EMAIL PROTECTED]> mo> Cc: <[EMAIL PROTECTED]> mo> Sent: Thursday, March 04, 2004 2:02 AM mo> Subject: Re[2]: [PHP] setting request variables But you are not posting to the login page ...you are including it so all the variables are available. $error only gets filled if there is an error, thats why in login.php we do a check to see if it is !empty() which would indicate something has gone wrong. Try this simplified code to demonstrate the flow: (validate.php) <?php if(isset($_POST['submit'])){ $error = ''; if($_POST['username'] != 'Fred'){ $error = '<font color="red"><b>Error: </b>You did not enter Fred</font>'; include('./login.php'); exit; }else{ ?> <html> <head> <title>Success</title> </head> <body> <h1> Welcome Fred</h1> </body> </html> <?php } }else{ include('./login.php'); } ?> (login.php) <html> <head> <title>Login</title> </head> <body> <form action="validate.php" method="post"> <table border="1"> <tr> <td>Login</td> </tr> <?php if(isset($error) && !empty($error)):?> <tr> <td><?php echo $error?></td> </tr> <?php endif?> <tr> <td><input type="text" name="username" value=""></td> </tr> <tr> <td><input type="submit" name="submit" value="submit"></td> </tr> </table> </form> </body> </html> Then go to validate.php or login.php it won't matter :) -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php