单击“确认”按钮后,我想执行这些操作。但我的代码不会在`if(isset($ _ POST ['confirm'])){..}之后运行 我真的会帮助你。
echo "<div class='container'>
<form action='confirm.php' method='post'>
<center><button type='button' name='confirm' value='confirm' class='btn btn-info btn-lg' data-toggle='modal' data-target='#myModal'>Confirm</button></center>
</form>
<div class='modal fade' id='myModal' role='dialog'>
<div class='modal-dialog'>";
if (isset($_POST['confirm'])){
$query2 = "SELECT status FROM reserver WHERE picker='$picking' AND droper='$droping'";
$result1 = mysqli_query($conn, $query2);
$row1=mysqli_fetch_assoc($result1);
$check_status=$row1['status'];
if($check_status=='available')
{
$query3 = "UPDATE reserver SET status='reserved' WHERE picker='$picking' AND droper='$droping'";
if(mysqli_query($conn, $query3)){
echo " <div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>Confirmation</h4>
</div>
<div class='modal-body'>
<p>Confirmed Sucessfully!</p>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div>";
}
}
else {
echo " <div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>Notice</h4>
</div>
<div class='modal-body'>
<p>Unavailable Vehicle!</p>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div>";
}
}
编辑:现在我有另外一个用于显示不可用车辆的案例
答案 0 :(得分:1)
您的解决方案无法打开带有成功消息的模式。您可以尝试这样的Pastebin Link
<?php
$status = false;
if (isset($_POST['confirm'])) {
$check_status = 'available';
$query2 = "SELECT status FROM reserver WHERE picker='$picking' AND droper='$droping'";
$result1 = mysqli_query($conn, $query2);
$row1=mysqli_fetch_assoc($result1);
$check_status=$row1['status'];
if($check_status=='available')
{
$query3 = "UPDATE reserver SET status='reserved' WHERE picker='$picking' AND droper='$droping'";
if(mysqli_query($conn, $query3)) {
$status = true;
}
}
}
?>
<div class='container'>
<form action='confirm.php' method='post'>
<center><button type='submit' name='confirm' value='confirm'>Confirm</button></center>
<button type='button' name='confirm' value='confirm' class='btn btn-info btn-lg' data-toggle='modal' data-target='#myModal' style="display:none;">Confirm</button>
</form>
<div class='modal fade' id='myModal' role='dialog'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
<button type='button' class='close' data-dismiss='modal'>×</button>
<h4 class='modal-title'>Confirmation</h4>
</div>
<div class='modal-body'>
<p>Confirmed Sucessfully!</p>
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
</div>
</div>
</div>
</div>
</div>
<?php if( $status == true ): ?>
<script>
$('.btn.btn-info').trigger('click');
</script>
<?php endif; ?>
答案 1 :(得分:0)
但是如果你想提交数据并通过php处理它,你想要做什么,你需要使用<input type='submit'/>
而不是按钮。
<input type="button" />
使用javascript并且不会提交表单。
<input type="submit" />
将提交表单。
但是AJAX就是为了这个,你只需要学习一些基础知识就可以了jQuery
所以这是示例如何工作
您首先需要创建一个简单的HTML表单
如果你想附加一些数据
<form method="POST" id="my_form">
<input type="hidden" name='test'/>
<input type="button" id="submit"/>
</form>
或者只是创建一个简单的按钮
<button id="click me" id="click_me"></button>
然后创建另一个HTML元素以显示用户响应状态
<div id="response"></div>
不可。所以现在我们完成了我们的HTML代码,让我们去编写一些jQuery代码
$(document).ready(function() {
$("#click_me").click(function() {
$.ajax({
url : "your_php_file.php", // file path you want to send data
type : "POST",
data : {},
success : function(data) {
$("#response").html("Confirmed Sucessfully!");
}
});
});
});
最后一件事是你的PHP代码
<?php
if() {
// your php code
}else{
header("HTTP/2.0 400 Bad request");
}
?>
这只是一个简单的解释,如何处理AJAX请求。您需要了解有关此内容的更多信息才能构建安全且有用的Web应用程序