DEV
DEV

Reputation: 667

PHP/MYSQL: Check whether email exists in database?

Having a bit of an issue validating the email address to check whether it exists in the database. It still submits the form. I don't know if it there is an issue with the query or if it just won't work. Any help will be greatly appreciated.

CODE:

<?php
if(isset($_POST['reg']))
{
$email = $_POST['login_email'];
$checkqry = "SELECT * from clinic_receptionist WHERE recep_email = '$email'";
$checkresult = mysqli_query($conn,$checkqry);
if(mysqli_num_rows($checkresult) > 0)
{
    echo "THE EMAIL ADDRESS IS IN USE";
}
}
?>
<form action="create_profile.php" method="post">

    <label>Email Address</label>
    <input type="email" name="login_email" id="login_email" class="form-control" placeholder="Email Address" required oninvalid="setCustomValidity('Please enter your email address')">
    <label>Password</label>
    <input type="password" name="password" class="form-control" placeholder="Password" required oninvalid="setCustomValidity('Please enter your password')">


    <input type="submit" name="reg" value="Register" class="btn btn-primary" style="margin-left:6%;">
<div style=" margin-top:4%;">
    <a href ="index.php" target="_blank" style="margin-left:6%;">Already have an Account? - Login</a>
</div>
</form>

Upvotes: 1

Views: 62

Answers (1)

Pathik Vejani
Pathik Vejani

Reputation: 4491

Query should be like this:

$email = $_POST['login_email'];
$checkqry = "SELECT * from clinic_receptionist WHERE recep_email = '$email' ";

Upvotes: 1

Related Questions