I am trying to store registration data into database but something I cannot quite understand keeps happening, the line below which is in my register.php form is printed out first before the HTML loads
query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . " " . $dbcon->error; } $dbcon->close(); } } ?>
Here is my code and I also would like to check if the email being used is registered, which in that case one should get an error saying 'Email is already registered'
Here is my PHP Code:
<?php
session_start();
if(isset($_SESSION['user'])!="")
{
header("Location: index.php");
}
include_once 'dbconnect.php';
if(isset($_POST['signup']))
{
//performing verfication
$upass = $_POST['upass'];
$pass2 = $_POST['pass2'];
if ($upass == $pass2){
$fullName=mysqli_escape_string($_POST['fullName']);
$tphon=mysqli_escape_string($_POST['telephone']);
$email=mysqli_escape_string($_POST['email']);
$role=mysqli_escape_string($_POST['role']);
$upass=mysqli_escape_string($upass);
$pass2=mysqli_escape_string($pass2);
$upass = crypt($upass);
$sql = "INSERT INTO users (fullname, telephone, email, role, pass)
VALUES ('$fullName', '$tphon', '$email', '$role', '$upass')";
if ($dbcon->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $dbcon->error;
}
$dbcon->close();
}
}
?>
and here is my HTML form:
<form id="wizardForm" action="register.php" method="POST">
<div class="row m-b-lg">
<div class="col-md-4 center">
<div class="login-box">
<a href="register.php" class="logo-name text-lg text-center">Timewise</a>
<p class="text-center m-t-md">Enter the following Details to Register</p>
</div>
<div class="form-group col-md-12">
<label for="exampleInputName">Full Name</label>
<input type="text" class="form-control" name="fullName" id="exampleInputName" placeholder="Full Name">
</div>
<div class="form-group col-md-12">
<label for="telephone">Telephone</label>
<input type="text" class="form-control" name="telephone" id="telephone" placeholder="Telephone" >
</div>
<div class="form-group col-md-12">
<label for="exampleInputEmail">Email Address</label>
<input type="email" class="form-control" name="email" id="exampleInputEmail" placeholder="Enter email" >
</div>
<div class="form-group col-md-12">
<label for="role">Role</label>
<input type="radio" name="role" value="N" /> NORMAL <input type="radio" name="role" value="C" /> COMPANY <br/>
</div>
<div class="form-group col-md-12">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" name="upass" id="exampleInputPassword1" placeholder="Password" >
</div>
<div class="form-group col-md-12">
<label for="exampleInputPassword2">Confirm Password</label>
<input type="password" class="form-control" name="pass2" id="exampleInputPassword2" placeholder="Confirm Password">
</div>
<div class="form-group col-md-12">
<input type="submit" name="signup" value="Submit" class="btn btn-success btn-block">
</div>
<p class="no-s text-center">2015 © Timewise Errand Services</p>
</div>
</div>
</form>
Kindly help!!!