note 21437 rejected from function.mysql-num-rows by sander
| From: | sander@php.net | Date: | Mon, 13 May 2002 12:41:46 +0000 |
| Subject: | note 21437 rejected from function.mysql-num-rows by sander | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-30585@lists.php.net to get a copy of this message | ||
I have tried all of these examples, but I can not get anything to work...
I keep getting a: "Warning: Supplied argument is not a valid MySQL result resource in
/home/cxb/public_html/auth.php on line 18"
This is my code....
<?php
if (!isset($PHP_AUTH_USER)) {
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
mysql_connect("localhost", "Blessed", "ultimasucks")
or die ("Unable to connect to database.");
mysql_select_db("Blessed")
or die ("Unable to select database.");
$sql = "select count(id) from users WHERE username='$PHP_AUTH_USER' and
password='$PHP_AUTH_PW'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if ($num != "0") {
echo "<P>You're authorized!</p>";
exit;
}
else {
header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
}
?>
My problem lies here : $num = mysql_num_rows($result);
But I con not figure out why... I saw all of your examples but nothing has worked.