donglianglu8136 2019-06-04 07:19
浏览 66
已采纳

数据库检查后模态未显示

I am trying to create a registration form. The condition is, if the person already registered, then the same person cannot be registered anymore.

What I Need

I have the following php MySQL query which checks if there is an existing entry present

  $duplicateCheckQuery = "SELECT * FROM registrationFormDetails WHERE email ='?' AND competition ='?'";
    $stmt = mysqli_stmt_init($conn);
    if(!mysqli_stmt_prepare($stmt, $duplicateCheckQuery)){
        echo "Duplicate check SQL statement failed";
    }else{
        mysqli_stmt_bind_param($stmt,"ss", $email, $competition);
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        $resultCheck = mysqli_num_rows($result);

        if($resultCheck>0){
            
            echo '<script>
            $("#exampleModal").modal("show")
            
            </script>';
         }else{
             //register
        }
      }

And I have the following modal codes which I copied from Bootstrap website

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

When I submit the form, I want the modal to appear. But it is not showing and instead it appears to be form is submitted. Does anyone know where am I getting wrong?

</div>
  • 写回答

2条回答 默认 最新

  • dsfdfdfd6576578 2019-06-20 08:37
    关注

    The correct answer is as follows. In fact the initial code can work by removing '' marks around the ? mark in the prepared statement. Also you can place the script inside a document.ready

      $duplicateCheckQuery = "SELECT * FROM registrationFormDetails WHERE email =? AND competition =?";
        $stmt = mysqli_stmt_init($conn);
        if(!mysqli_stmt_prepare($stmt, $duplicateCheckQuery)){
            echo "Duplicate check SQL statement failed";
        }else{
            mysqli_stmt_bind_param($stmt,"ss", $email, $competition);
            mysqli_stmt_execute($stmt);
            $result = mysqli_stmt_get_result($stmt);
            $resultCheck = mysqli_num_rows($result);
    
            if($resultCheck>0){
                
                echo '<script>
                $("#exampleModal").modal("show")
                
                </script>';
             }else{
                 //register
            }
          }

    Then give modal codes

    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            ...
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作