problems with if/then statement
| From: | Colin Gray | Date: | Tue, 27 Jun 2000 19:49:45 +0000 |
| Subject: | problems with if/then statement | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3477@lists.php.net to get a copy of this message | ||
I am trying to set up a login page, where the user logs in with their
name/password, and the values are then sent to a page that verifies the
name/password, and then gives the appropriate content. I also want to set a
cookie if the login is successful. The following code is located at the
very top of the page (so the cookie can be set):
<?
mysql_connect("localhost", "chauness", "******")
or die ("Unable to connect to server.");
mysql_select_db("chaunessy_com")
or die ("Unable to select database.");
$sql = "SELECT member_id
FROM gcyo
WHERE member_id='$username' and member_pass='$password'";
$result = mysql_query($sql)
or die ("Unable to get results.");
$num = mysql_numrows($result)
or die ("You're not authorized to be here. If you feel you have
received this message in error, please contact the webmaster");
if ($num == 1)
{
setcookie("gcyousername",$username,time()+3600);
$login_success=1;
} else {
$login_success=0;
}
?>
The problem I am having is, when the login is incorrect, it dies at the
statement "$num = mysql_numrows($result)". What is supposed to happen is if
the login is incorrect, it is supposed to pass a value of 0 for the variable
$login_success to be used for content display further down the page. Why is
it throwing an error there?? is there a problem in my syntax??
Thanks in advance for your help!
Colin Gray
chaunessy creative web solutions
www.chaunessy.com
cgray@chaunessy.com
Pager: 864.410.8243