...

View Full Version : PEAR DB Login Script



Goober
01-06-2004, 04:05 AM
the variable "$count" allways returns as 0 making the login a failure. where is my error?




if(empty($_POST['name']) || empty($_POST['pass']))
{ ?>
<b>Fill All Details </b>
<?php exit;
}
else
{
//Colllect the details and validate
$time = time();
$name = $_POST['name'];
$pass = md5($_POST['pass']);
$check = $_POST['set'];

//Run Query
$stmt = "SELECT * FROM {$tb_prefix}users where username='$name' and password='$pass'";
$sql = $dbh->getAll($stmt, DB_FETCHMODE_ASSOC);

//Error Message
if (PEAR::isError($sql)) {
echo "An error occurred while trying to run your query.";
exit;}

//Counts Rows
$count = count($sql);

echo "$count<br>";
echo "$sql<br>";

if ($count == 1)
{
$cookie_data = $name.'-'.$pass;
if($check=='ON')
{
if(setcookie ("cookie_info",$cookie_data, $time+3600)==TRUE)
{
echo "Cookie SET".$cookie_data; ?>
<a href='logout.php'>Logout</a>

<? }
}
}
else
{
echo "Authentication Failed";
exit;
}

}
?>



why dose $count allways equal zero when it should equal one?where is the error?

mordred
01-06-2004, 02:00 PM
Perhaps no result is found for the SQL query? Have you printed out the generated query and run that through phpMyAdmin, to see if the result is as expected? That's the only possible explanation I have so far, your DB code looks ok otherwise.

Goober
01-07-2004, 02:04 AM
hmm i guess it has something to do with md5 encryption. i think i might have messed up with that. i'll have to check again i guess...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum