表单变量与数据库表匹配

时间:2016-07-15 06:08:44

标签: php

我有一个注册表单,其中包含电子邮件ID和手机号码。如果有人输入电子邮件和电话号码,那么它将匹配数据库表移动电话和电子邮件。如果电子邮件或手机匹配,则条件另有条件。我试过但它不起作用。

        if(isset($_POST["submit"]))
                            {

                                require"connection.php";
                                extract($_POST);

                                $result12=mysql_query("select mobile,email from mainaccount") or die (mysql_error());
                                while($row12=mysql_fetch_array($result12))
                            {

                                if($username==$row12["mobile"] || $email==$row12["email"])
                                {
                                echo"<b>Your Mobile number OR Email exists. Please use another Mobile number or Email!!!</b>";
                                die();
                                }

                                }

             <form method="post" id="loginForm" name="loginForm" action="" onsubmit="return executeOnSubmit();">
            <div class="col-lg-4">
                    Mobile No.&nbsp;<span style="color:red">*</span>
                    </div>
                    <div class="col-lg-8">
                    <input type="number" class="form-control" value="" name="username"  id="username" required  />
                    <div id="status"></div>
                    </div>
                <div class="col-lg-4">
                    Email.&nbsp;<span style="color:red">*</span>
                    </div>
                    <div class="col-lg-8">
                    <input type="email" class="form-control" value="" name="email"  id="email" required  />
                    <div id="status"></div>
                    </div>
            <div class="col-lg-12-pull-right">
                    <input type="submit" class="btn btn-success" value="Register" name="submit"   />
                    <span style="margin-left:330px;"><b style="color:red">*</b> Means compulsary fields.</span>
                    </div>

                    </form>

2 个答案:

答案 0 :(得分:1)

如果要检查是否有这样的用户,则无法使用此条目。您需要添加查询“SELECT mobile,email from mainaccount WHERE mobile = $ mobile OR email = $ username”条件并检查PHP端并且表格不为空或向条件添加条件“SELECT COUNT(*)as mainaccount WHERE mobile = $ mobile OR email = $ username”,并检查数据库的返回值是否大于0.但是,如果要检索所有的记录并检查side php是否你必须使用循环然后比较值并停止循环,如果比较返回true并且你做下一个有趣的事情。

答案 1 :(得分:0)

无需从数据库中获取所有记录。试试这个=

    $result12 = mysql_query("SELECT count(*) from mainaccount where email = '$email' or mobile = '$mobile'");
        $row12 = mysql_fetch_assoc($result12);
        if($row12['count(*)']>0)
            {
                echo"<b>Your Mobile number OR Email exists. Please use another Mobile number or Email!!!</b>";
                die();
            }