Hi guys, So I'm trying to create a PHP Signup page, of which I though I was doing well, but once I click Register on the Form instead of hte User being created in the database, it instead produces the following error:
PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/davarie.com/public_html/pages/signup.php on line 53, referer: http://davarie.com/pages/signup.php
I was creating this contact form via Bootstrap, and learnt the below via a book I was reading.
Below is my Signup.php file:
<?php
include('header.php');
if ($_SERVER['REQUEST_METHOD']=='POST')
{
#statements to run
require ('../connect_db.php');
$error = array();
#Requires First_name
if ( empty($_POST['first_name']))
{$errors[] = 'Enter your first name.';}
else
{$fn = mysqli_real_escape_string($dbc,
trim($_POST['first_name']));}
#Requires surname
if ( empty($_POST['surname']))
{$errors[] = 'Enter your surname.';}
else
{$sn = mysqli_real_escape_string($dbc,
trim($_POST['surname']));}
#Requires email_address
if ( empty($_POST['email']))
{$errors[] = 'Enter your email_address.';}
else
{$ea = mysqli_real_escape_string($dbc,
trim($_POST['email']));}
#Requires password, also the checks to ensure that password and password confirmation match starts here.
if ( !empty( $_POST['password']))
{
if ( $_POST['password']!= $_POST['password_confirmation'])
{ $errors[] = '<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Warning! Passwords do not match.
<a href="login.php">Login</a> </div>';}
else
{$p = mysqli_real_escape_string($dbc,
trim($_POST['password']));}
}
else { $errors[] ='Enter your password.';}
#Checks to ensure email address isn't already in use.
if (empty($errors))
{
$q = "SELECT user_id FROM users WHERE email='$ea'";
$r = mysqli_query ($dbc,$q);
if ( mysqli_num_rows($r)!=0)
{ $errors[] = '<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
Warning! Email Address already registered.
<a href="login.php">Login</a> </div>';}
}
#Inserts the registration data into the database
if ( empty($errors))
{
$q = "INSERT INTO users
(frist_name, surname, email, password, reg_date)
VALUES ('$fn','$sn','$ea', SHA1('$p'), NOW())";
$r = mysqli_query ($dbc, $q);
if ($r)
{
echo '<div class="alert alert-success">
Success! Account has been created.
<br>
<p1> <a href="login.php">Login</a></p>
</div>';
}
#Closes the Database connection
mysqli_close( $dbc);
exit();
}
#Displays any errors with the registration.
else
{
echo ' <div class="alert alert-danger">
Error! <p id="err_msg">The following error(s) occurred:<br>';
foreach ( $errors as $msg)
{
echo "- $msg<br>";
}
echo'Please try again.</p>
</div>';
mysqli_close( $dbc);
}
}
?>
<br>
<br>
<br>
<div class="container">
<div class="row centered-form">
<div class="col-sm-10">
<div class="panel panel-default">
<div class="panel-heading">
<h1 class="panel-title">Sign-up <small>please fill in the details below accurately</small></h1>
</div>
<div class="panel-body">
<form role="form" method="post">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="first_name" id="first_name" class="form-control input-sm" placeholder="First Name">
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="surname" id="surname" class="form-control input-sm" placeholder="Surname">
</div>
</div>
</div>
<div class="form-group">
<input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address">
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-sm" placeholder="Password">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-sm" placeholder="Confirm Password">
</div>
</div>
</div>
<input type="submit" value="Register" class="btn btn-success btn-block">
</form>
</div>
</div>
</div>
</div>
</div>
</body>
<?php include('footer.php');?>