数据库检查后模态未显示

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>

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>

The modal is getting initialized before the window fully get loaded, that's why it's not working. so you can change your code to this one, it works perfectly

echo '<script>
        $(document).ready(function(){
            $("#exampleModal").modal("show")
        });
        </script>';