rubbersoul
IS-IT--Management
setting up a web site and want to have users register to get on. I created a teble with a couple of fields and inserted some test users. I use a script in PHP to connect to the db and propmt you for user name and password. When I enter one of them (the good ones, or a bad one) I get:
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource Here is my code...can anyone help?
<?php
// File Name: 123
// Check to see if $PHP_AUTH_USER already contains info
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('Dosent matter');
header('Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
// If non-empty, check the database for matches
// connect to MySQL
mysql_connect("?", "?", "?"
or die ("Unable to connect to database."
// select database on MySQL server
mysql_select_db("?_com"
or die ("Unable to select database."
// Formulate the query
$sql = "SELECT *
FROM users
WHERE username='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_numrows($result);
if ($num != "0" {
echo "<P>You're authorized!</p>";
exit;
} else {
header('dosent matter');
header('?');
echo 'Authorization Required.';
exit;
}
}
?>
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource Here is my code...can anyone help?
<?php
// File Name: 123
// Check to see if $PHP_AUTH_USER already contains info
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('Dosent matter');
header('Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
// If non-empty, check the database for matches
// connect to MySQL
mysql_connect("?", "?", "?"
or die ("Unable to connect to database."
// select database on MySQL server
mysql_select_db("?_com"
or die ("Unable to select database."
// Formulate the query
$sql = "SELECT *
FROM users
WHERE username='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_numrows($result);
if ($num != "0" {
echo "<P>You're authorized!</p>";
exit;
} else {
header('dosent matter');
header('?');
echo 'Authorization Required.';
exit;
}
}
?>