Gossamer Forum
Home : General : Databases and SQL :

PHP / MySQL help

Quote Reply
PHP / MySQL help
Hey guys got a problem with MySQL statement.

I'm just a beginner and i'm trying to setup a template for a site I would like designed. I am at trying to get a login page to work in PHP / MySQL.

However I am getting an error when I try logging in.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/aboutstb/public_html/test/login.php on line 8

<?
include ("includes/db.php");
if (($username) AND ($password)) {
// you should inspect these variables before passing off to mySQL
$query = "SELECT username, password FROM user ";
$query .= "WHERE user='$username' AND pass='$password'";
$result = mysql_query($query, $dbh);
if(mysql_num_rows($result)) {
// we have at least one result, so update the logged in datetime
$query = "UPDATE from login SET logged=SYSDATE()";
$query .= "WHERE user='$username' AND pass='$password' ";
mysql_query($query,$mysql_link);
} else {
print("Sorry, this login is invalid.");
exit;
}
} else {

?>
<form action="<? echo $PHP_SELF?>" method="POST">
User: <input type="text" name="username">
Pass: <input type="password" name="password">
<input type="submit" value="Submit"></form>
<?
}
?>

The include for the database connection is correct. So it's not there it's after somewhere on line 8 which is the following line:

if(mysql_num_rows($result))

Any help would be greatly appreciated.

Nick
Quote Reply
Re: [nickXrider] PHP / MySQL help In reply to
I'm guessing mysql_query failed causing $result to contain nothing.

Use some error checking =)
Quote Reply
Re: [Paul] PHP / MySQL help In reply to
In Reply To:
I'm guessing mysql_query failed causing $result to contain nothing.

Use some error checking =)


You was 100% right Wink lol I overlooked a few things. Like I said i'm new at this lol. Well after all that hasle the script sux.. I need something that I can use so when I login it will take me to the next page and on that next page it will do a quick check to make sure that the user is logged in and if he/she isn't then to boot them out to the loggin page.

Anyone know of a good script I can use for this (that is half simple) remember i'm semi retarded at this lol.

Thanks

Nick
Quote Reply
Re: [nickXrider] PHP / MySQL help In reply to
Mmm...not sure. I would recommend adding some error checking after the SQL query. Something like this should work;

Code:
$error = mysql_error();

if ($error) {
echo "There was an SQL error. It was: $error";
exit;
}

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates