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:
<?php
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 '<META HTTP-EQUIV="REFRESH" CONTENT="5;URL=page to set password.">';
}
}
}
?>
Form code:
<form class="no-margin" method="post">
<fieldset>
<div class="form-group no-margin">
<label for="username" >Username</label>
<div class="input-group input-group-lg">
<span class="input-group-addon">
</span>
<input id="username" type="username" name="username" class="form-control input-lg" placeholder="Username">
</div>
</div>
<div class="form-group">
<label for="Email" >Email</label>
<div class="input-group input-group-lg">
<span class="input-group-addon">
</span>
<input id="email" type="email" name="email" class="form-control input-lg"
placeholder="Email">
</div>
</div>
</fieldset>
<div class="form-actions">
<button type="submit" name="submit" class="btn btn-block btn-lg btn-danger">
</span>
<small>Submit</small>
</button>
<div class="forgot"><a href="not important">Not a member? Join here!</a></div>
</div>
</form>
$usernamemight not be set$dbinit line, since the query seems to look ok$check->bind_param(":username",$username);Bill's answer?