I hope someone can help with this, I'm trying to setup a login script using php and Mysql. It seems to be working fine apart from when you try to login. After logging in it through's up this message
Fatal error: Call to a member function on a non-object in /path/to/public_html/test/login.php on line 35
The code is this...
<?php
// database connect script.
require 'db_connect.php';
if($logged_in == 1) {
die('You are already logged in, '.$_SESSION['username'].'.');
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
if (isset($_POST['submit'])) { // if form has been submitted
/* check they filled in what they were supposed to and authenticate */
if(!$_POST['uname'] | !$_POST['passwd']) {
die('You did not fill in a required field.');
}
// authenticate.
if (!get_magic_quotes_gpc()) {
$_POST['uname'] = addslashes($_POST['uname']);
}
// the below line is line 35, where the error occurs
$check = $db_object->query("SELECT author_name, author_password FROM mt_user WHERE author_name = '".$_POST['uname']."'");
if (DB::isError($check)) {
die('That username does not exist in our database.');
}
$info = $check->fetchRow();
// check passwords match
$_POST['passwd'] = stripslashes($_POST['passwd']);
$info['author_password'] = stripslashes($info['author_password']);
$_POST['passwd'] = md5($_POST['passwd']);
if ($_POST['passwd'] != $info['author_password']) {
die('Incorrect password, please try again.');
}
// if we get here username and password are correct,
//register session variables and set last login time.
$date = date('d m, Y');
$update_login = $db_object->query("UPDATE mt_user SET last_login = '$date' WHERE author_name = '".$_POST['uname']."'");
$_POST['uname'] = stripslashes($_POST['uname']);
$_SESSION['username'] = $_POST['uname'];
$_SESSION['password'] = $_POST['passwd'];
$db_object->disconnect();
?>
<h1>Logged in</h1>
<p>Welcome back <?php echo $_SESSION['username']; ?>, you are logged in.</p>
<?php
} else { // if form hasn't been submitted
?>
<h1>Login</h1>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table align="center" border="1" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td>
<input type="text" name="uname" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="passwd" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}
?>
</body>
</html>
I've no idea why the message comes up, I read somewhere it could be because I use the same variables twice and they clash, but I've checked and that isn't happening. Hope someone can help
Thanks.