检查数据库中是否已存在电子邮件 - 无效

时间:2015-02-10 11:36:45

标签: php validation

我正在尝试检查注册时数据库中是否已存在电子邮件,但我无法使其正常运行。尽管我为此付了支票,但它没有检查电子邮件是否存在。非常感谢任何帮助。

<?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: ";
    }
        }
?>

1 个答案:

答案 0 :(得分:0)

使用此查询:

$check="SELECT COUNT(email) FROM applications WHERE email = '$email'";