View Full Version : PEAR DB Login Script

01-06-2004, 03: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;
//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.";

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

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

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

<? }
echo "Authentication Failed";


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

01-06-2004, 01: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.

01-07-2004, 01: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