I'm working on a dashboard for someone and i'm getting an error. I'm creating a registration page and what it does is it looks to see if the users already in the database, if it is then it allows them to complete the registration, but when I submit, it creates this error Fatal error: Call to a member function bind_param() on a non-object on line 8
Heres the PHP code:
include"core/config.php";
if(isset($_POST['submit']))
{
$username = $_POST['username'];
$email = $_POST['email'];
$check = $db->prepare("SELECT * FROM users WHERE username = :username");
$check->bind_param(":username",$username);
$check->execute();
echo $check->error;
$emailCheck = null;
$usernameCheck = null;
while($row = $check->fetch())
{
$emailCheck = $row['email'];
$usernameCheck = $row['username'];
}
if(!$email == $emailCheck)
{
echo 'Email doesn\'t exist!';
}else{
if(!$username == $usernameCheck)
{
echo 'Username doesn\'t exist!';
} else
{
$query = $db->prepare("SELECT * FROM users WHERE username = :username AND email = :email");
$query->bind_param(":username", $username);
$query->bind_param(":email", $email);
$query->execute();
$_SESSION['username'] = $username;
echo 'You have logged in, you will be redirected.';
echo '';
}
}
}
?>
Form code:
No comments:
Post a Comment