Web Hosting Talk







View Full Version : PHP -- can anyone help?


zRedDice
07-17-2002, 12:02 AM
Well... I've spent 3 hours looking at it... I checked spelling, syntax, and logic, and it all gives the same error.

It is part of a page object, in which all of the functions are defined and work fine. The query executes with no problem, but then it gets an error on the mysql_num_rows() line, saying that $result is not a valid result identifier. Anyone know why?


function checkauth()
{
global $PHP_AUTH_USER, $PHP_AUTH_PW, $PHP_SELF;
global $userid, $password, $username, $userconame;

if(!isset($username))
{
$this->startpage();
$this->loginpage();
$this->endpage();
exit;
}
else
{
session_register($password, $username);
$query = "SELECT id, name FROM companies WHERE username='$username' AND password=password('$password')";
$result = mysql_query($query, $this->conn);
if(!mysql_num_rows($result))
{
session_unregister($password);
session_unregister($username);

$this->startpage();
$this->loginpage();
$this->endpage();
}
else
{
$record = mysql_fetch_object($result);
$userconame = $record->name;
$userid = $record->id;
}
}
}

Studio64
07-17-2002, 12:52 AM
This should be in the tech section.... :D...

But, at first glance try changing


$query = "SELECT id, name FROM companies WHERE username='$username' AND password=password('$password')";


to:


$query = "SELECT id, name FROM `companies` WHERE username='$username' AND password=password('$password')";


The `(top left key on the keyboard) marks around companies.... Small error but, MySQL is really finnicky, I'm sure you know this as well....

Add that to PHP's weird error handling and sometimes little things like that can trip things up...

See if that works...

iamdave
07-17-2002, 12:57 AM
Originally posted by Studio64
This should be in the tech section.... :D...

But, at first glance try changing


$query = "SELECT id, name FROM companies WHERE username='$username' AND password=password('$password')";


to:


$query = "SELECT id, name FROM `companies` WHERE username='$username' AND password=password('$password')";


The `(top left key on the keyboard) marks around companies.... Small error but, MySQL is really finnicky, I'm sure you know this as well....

Add that to PHP's weird error handling and sometimes little things like that can trip things up...

See if that works... You really don't need to add the "`" his query should work fine.