提问人:Kucen 提问时间:11/2/2023 最后编辑:Kucen 更新时间:11/2/2023 访问量:39
将数据插入数据库后如何弹出模态成功或错误?
How to pop up a modal successful or error after inserted data into database?
问:
我想在用户将数据插入数据库时生成一个弹出模式,或者错误消息成功。下面我有一个表单,两个模态和php代码,用于将数据从表单插入数据库。我所做的,我将成功设置为 true 到 tambahnotisphp.php,但它什么也没做。
如何在用户将数据更新到数据库后弹出模式消息。当用户输入表单并点击提交时。然后检查数据是否成功插入数据库,会弹出成功模态,但如果数据插入数据库不成功,会弹出不成功/错误模态。
//tambahnotis.php
<script type="text/javascript">
<?php
if ($_GET['sucsess'] == 'true'){
echo '$(document).ready(function() {
$( "#modal-small" ).dialog();
});';
}
?>
</script>
<form class="card" action="tambahnotisphp.php" method="post" enctype="multipart/form-data" runat="server" >
<div class="card-body">
<div class="mb-3">
<div class="form-label required">Nombor Fail</div>
<input type="text" class="form-control" name="nomborFail" id="nomborFail" required="" onkeyup="checkUsername(this.value);">
<div id="uname_response" ></div>
</div>
<div class="mb-3">
<div class="form-label required">Ulasan</div>
<textarea class="form-control" id="ulasan" name="ulasan" rows="4" cols="50" required=""></textarea>
</div>
<div class="mb-3">
<div class="form-label required">Tarikh Notis Siasatan Dikeluarkan</div>
<input type="date" class="form-control" name="tarikhNotisKeluar" id="tarikhNotis1" required=""/>
</div>
<div class="card-footer">
<div class="row align-items-center">
<div class="col"></div>
<div class="col-auto">
<button type="submit" name="submit" class="btn btn-primary btnTambahNotis">Tambah Notis</button>
</div>
</div>
</div>
</div>
</form>
<div class="modal modal-blur fade" id="modal-small" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="modal-title">Success</div>
<div>Notis Siasatan berjaya ditambah</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-bs-dismiss="modal">Okay</button>
</div>
</div>
</div>
</div>
<div class="modal modal-blur fade" id="modal-small2" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-body">
<div class="modal-title">Error</div>
<div>Notis Siasatan tidak berjaya ditambah</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-bs-dismiss="modal">Okay</button>
</div>
</div>
</div>
</div>
<?php
//tambahnotisphp.php
include('connection.php');
$conn=Connect();
$idPengguna = "DI200017";
$nomborFail = $conn->real_escape_string($_POST['nomborFail']);
$ulasan = nl2br($_POST['ulasan']);
$status = "BELUM SELESAI";
$tarikhNotisKeluar = $conn->real_escape_string($_POST['tarikhNotisKeluar']);
// Add 30 days to the date
$futureDate30Days = date('Y-m-d',strtotime($tarikhNotisKeluar . ' +30 days'));
$futureDate60Days = date('Y-m-d',strtotime($tarikhNotisKeluar . ' +60 days'));
$query = "INSERT INTO notis(nomborFail, ulasan, tarikhNotisKeluar, tarikhNotis1, tarikhNotis2, status, idPengguna) VALUES('" . $nomborFail . "','" . $ulasan . "','" . $tarikhNotisKeluar . "','" . $futureDate30Days . "','" . $futureDate60Days . "','" . $status . "','" . $idPengguna . "')";
$success = $conn->query($query);
if ($success){
header("Location: tambahnotis.php?sucsess=true");
$conn->close();
}else{
die("Data Notis Siasatan tidak dapat ditambah: ".$conn->error);
}
?>
答: 暂无答案
评论