我正在尝试创建注册表。条件是,如果该人已经注册,则该人不能再注册。
我需要的
我有以下php MySQL查询,用于检查是否存在现有条目
$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
}
}
我从Bootstrap网站复制了以下模式代码
<!-- 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">×</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>
提交表单时,我希望出现模式。但是它没有显示,而是似乎已提交表单。有人知道我在哪里错吗?
答案 0 :(得分:1)
模态在窗口完全加载之前被初始化,这就是为什么它不起作用的原因。因此您可以将代码更改为此代码,它可以完美运行
echo '<script>
$(document).ready(function(){
$("#exampleModal").modal("show")
});
</script>';
答案 1 :(得分:0)
正确答案如下。实际上,初始代码可以通过删除?周围的'标记来起作用。在准备好的语句中标记。您也可以将脚本放在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
}
}
然后给出模态代码
<!-- 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">×</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>