PDA

View Full Version : Another php problem



mlowery
March 21st, 2004, 03:18
I am making a very simple password page which uses the user_name and password that a member who registered submitted to the mysql database.


<?

header("Cache-control: private");

$user_name = $POST_['user_name'];
$password = $POST_['password'];
$encpassword = md5($password);

$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

$login = $dbs->select("SELECT * FROM $dbtbl[roster] WHERE screen_name = '$user_name' && password = '$encpassword'");

if(isset($login)) //login was succcesful
{
header("Location: http://mlowery.net/AC/");
}
else // login was not succesful
{
echo('Wrong User Name or Password');
};

?>

I get this error:


Fatal error: Call to a member function on a non-object in /home/mlowery/public_html/AC/login_processor.php on line 12

Really what I'm doing is making sure the user_name and password submitted on the form are equal to the ones in the data base. If they are, then it reloads to a new page. If not, an error page comes up. Can you please tell me what I am missing?

For some reason, the forum is inserting link tags into my php script on the header() tag. Disregard this. The problem is in this line:


$login = $dbs->select("SELECT * FROM $dbtbl[roster] WHERE screen_name = '$user_name' && password = '$encpassword'");

bloodyveins
March 21st, 2004, 06:17
troubleshooting:
when you declare

$dbs = new XYZ; //XYZ is your database loader class
make sure function select exists in it ($dbs , or pointer to class XYZ)

mlowery
March 21st, 2004, 15:34
Thanks. I got it working. I just took out that part and changed it to mysql_query (which I should have done to begin with).
Here is the final script:


<?

header("Cache-control: private");

$user_name = $POST_['user_name'];
$password = $POST_['password'];
$encpassword = md5($password);

$dbh=mysql_connect ("localhost", "user", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database");

$login = mysql_query("SELECT * FROM $dbtbl[roster] WHERE screen_name = '$user_name' && password = '$encpassword'");

if(isset($login)) //login was succcesful
{
header("Location: http://mlowery.net/AC/");
}
else // login was not succesful
{
echo('Wrong User Name or Password');
};

?>