donglu3087 2016-07-15 06:08
浏览 26
已采纳

表单变量与数据库表匹配

I have a signup form in which email id and mobile number present. If any one enter email and phone number then it will match from database table mobile and email. If email or mobile matches then if condition otherwise else condition. I tried but its not working.

        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条回答 默认 最新

  • dongyihao9887 2016-07-15 06:28
    关注

    You can not use this entry if you want to check if there is such a user. You need to add to the query "SELECT mobile,email from mainaccount WHERE mobile = $mobile OR email = $username" condition and check the PHP side and the table is not empty or add a condition to the "SELECT COUNT(*) as count from mainaccount WHERE mobile = $mobile OR email = $username" and check the return value from the database is greater than 0. However, if you want to retrieve all the records and check for side php whether you there is you have to use a loop and subsequently compare the values and stop loops if the comparison returns true and you do next interesting things.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配