-4

I am trying to check if an email already exists in the database when signing up, but I can't make it work. Despite the check I put in for it, it's not checking if the email alreayd exists. Would greatly appreciate any help.

<?php 
    if(!empty($_POST)){
        $email = $_POST['email'];
        $question1 = $_POST['question1']; 
        $question2 = $_POST['question2']; 
        $question3 = $_POST['question3']; 
        $question4 = $_POST['question4']; 
        $question5 = $_POST['question5']; 
        $question6 = $_POST['question6']; 
        $question7 = $_POST['question7']; 
        $question8 = $_POST['question8']; 
        $question9 = $_POST['question9']; 
        $question10 = $_POST['question10']; 
        $question11 = $_POST['question11']; 
        $question12 = $_POST['question12']; 
        $question13 = $_POST['question13']; 
        $question14 = $_POST['question14']; 
        $question15 = $_POST['question15']; 

    }

        $mysqli = new mysqli('localhost', 'root', '', 'database');

        $check="SELECT * FROM applications WHERE email = '$email'";
        $rs = mysqli_query($mysqli,$check);
        $data = mysqli_fetch_array($rs, MYSQLI_NUM);
        if($data[0] > 1) {
            echo "User Already in Exists<br/>";
        }
        else
        {

        $queryResult =  $mysqli->query("INSERT INTO applications(email, question1, question2, question3, question4, question5, question6, question7, question8, question9, question10, question11, question12, question13, question14,question15) VALUES ('$email', '$question1', '$question2', '$question3', '$question4', '$question5', '$question6', '$question7', '$question8', '$question9', '$question10','$question11', '$question12', '$question13','$question14', '$question15')");

if ($queryResult === TRUE) {
    echo"<div class='container padtop100'>
            <div class='row'>
                <div class='col-lg-12'>
                    <div class='panel panel-default'>
                        <div class='panel-heading'>
                            <h3 class='panel-title uppercase'>
                                Success!
                            </h3>
                        </div>
                        <div class='panel-body'>
                            <span>Thank your for your application, ${question1}.</span><br /><br />Your application has now been recorded, and is pending review. You will be notified via email on how to proceed, once your application has been reviewed. You may also check the status on your application <a href='index.php/index'>here</a>.</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>";
    } else {
    echo "Error: ";
    }
        }
?>
Shepred
  • 5
  • 2
  • possible duplicate of [Check if username already exists in database MySQL PHP](http://stackoverflow.com/questions/8611044/check-if-username-already-exists-in-database-mysql-php) – B001ᛦ Feb 10 '15 at 11:37

1 Answers1

0

use this query:

$check="SELECT COUNT(email) FROM applications WHERE email = '$email'";
John V
  • 875
  • 6
  • 12