Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new to mysql

Status
Not open for further replies.

rubbersoul

IS-IT--Management
Mar 20, 2003
88
CA
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(&quot;?&quot;, &quot;?&quot;, &quot;?&quot;)

or die (&quot;Unable to connect to database.&quot;);

// select database on MySQL server

mysql_select_db(&quot;?_com&quot;)
or die (&quot;Unable to select database.&quot;);

// Formulate the query

$sql = &quot;SELECT *
FROM users
WHERE username='$PHP_AUTH_USER' and password='$PHP_AUTH_PW'&quot;;



// 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 != &quot;0&quot;) {
echo &quot;<P>You're authorized!</p>&quot;;
exit;

} else {

header('dosent matter');
header('?');
echo 'Authorization Required.';
exit;

}

}



?>
 
Insufficient data for a meaningful answer.

&quot;Not a valid resource handle&quot; errors happen when a query fails for syntactical reasons, but you do not check for errors.

I have a FAQ on debugging in the PHP forum which has a section on debugging database access problems. faq434-2999

Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top