Thanks for your reply,

I am still a bit confused though as the var error is never set! i.e. in your
code example below $error is never going to be set! Basically I have 2 pages
as follows:

page1.php - login form page
page2.php - validation page

page2.php checks the usernae and password against database and if all is
well it sends to the members area. If there was an error then it sends back
to the login page. When there is an error on page2.php I want to set a
request variabel called "$someError" with a value representing the error
that occured i.e. "Please enter a username" or "Please enter a password" or
"Invalid username" or "invalid password" etc.. Then on page1.php just before
the login form I would do:

if (!empty($_POST('someError'))) {
  echo $_POST('someError');
}
//display login form.

So my question is how do I add the variable $someError to the request with
the value "invalid usernam" and disaply this on page1.php

   $error = ''; //assume no errors
   if(isset($_PHP['password'] && !empty($_POST['username']){
    $sql = "SELECT id FROM members WHERE
    username = '".$_POST['username']."'
    AND password = '".$_POST['password']."'";
     $result = mysql_query($sql);
     if(!$mysql_num_rows($result) > 0){
      $error = '<font color="red"><b>Error:</b> Invalid password</font>';
      include('login.php');
      exit;
    }
   //password ok
   echo 'Welcome '.$_POST['username'].'<br>';
 }else{
  //first pass and $error is still empty
  include('login.php');
 }
----- Original Message ----- 
From: "Tom Rogers" <[EMAIL PROTECTED]>
To: "matthew oatham" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, March 04, 2004 2:02 AM
Subject: Re[2]: [PHP] setting request variables


> Hi,
>
> Thursday, March 4, 2004, 11:08:06 AM, you wrote:
> mo> but what if I wanted the variable $error to be a message. I want to
set a
> mo> variable called $error to something like "invalided password" then
display
> mo> this on the login page.
>
> mo> Cheers
>
> mo> Matt
> 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 12:24 AM
> mo> Subject: Re: [PHP] setting request variables
>
>
> >> Hi,
> >>
> >> Thursday, March 4, 2004, 9:08:19 AM, you wrote:
> >> mo> Hi,
> >>
> >> mo> I have created a small login system for my website. However
> >> mo> if a user logs in incorrectly I want to display a error message
> >> mo> currently I use the code
> >>
> >> mo>     echo "You could not be logged in! Either the username and
> >> mo> password do not match or you have not validated your membership!
> >> mo> <br />
> >> mo>     Please try again! <br />";
> >> mo>     include  ("login.php");
> >>
> >> mo> However this appears at the top of my website but I want it
> >> mo> to appear above the login form so I though I could set a variable
> >> mo> in the request called "error" or similar then on the login page
> >> mo> just above the login form check for the presence of the request
> >> mo> variable "error" and print the appropriate message. So I want to
> >> mo> do the following:
> >>
> >> mo>     SET REQUEST VARIABLE ERROR HERE
> >> mo>     include  ("login.php");
> >>
> >> mo> But can I set a request variable? i.e in JAVA I would do
> >> mo> HttpRequest.setAttribute("error", true); etc..
> >>
> >> mo> Any help?
> >>
> >> mo> Cheers
> >>
> >> add something like this to login.php
> >>
> >> if(!empty($error)){
> >>   echo '<tr><td>'.$error.'</td></tr>';
> >> }
> >>
> >> as it is included it will have $error available to it
> >> -- 
> >> regards,
> >> Tom
> >>
> >> -- 
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >>
>
>
> well that would be easy, for example
>
> $error = ''; //assume no errors
> if(isset($_PHP['password'] && !empty($_POST['username']){
>   $sql = "SELECT id FROM members WHERE
>   username = '".$_POST['username']."'
>   AND password = '".$_POST['password']."'";
>   $result = mysql_query($sql);
>   if(!$mysql_num_rows($result) > 0){
>     $error = '<font color="red"><b>Error:</b> Invalid password</font>';
>     include('login.php');
>     exit;
>   }
>   //password ok
>   echo 'Welcome '.$_POST['username'].'<br>';
> }else{
>  //first pass and $error is still empty
>  include('login.php');
> }
> -- 
> regards,
> Tom
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to