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