我们有一个程序有两个按钮(批准和拒绝)。我们的问题是当我点击按钮时,提示符上的值不会保存在数据库中。
ServiceRequest.php
<?php
session_start();
if(!isset($_SESSION['user']) || !isset($_SESSION['lname']) || !isset($_SESSION['fname']) || !isset($_SESSION['lname']) || !isset($_SESSION['pass']) || !isset($_SESSION['assign']) || !isset($_SESSION['department']) || !isset($_SESSION['branch']) || !isset($_SESSION['province']) || !isset($_SESSION['position']))
{
header('Location:login.php');
}
include 'config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="image/fblogo.ico">
<title>FB | ITS&CMS</title>
<link href="dist/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- <link href="signin.css" rel="stylesheet"> -->
<link rel="stylesheet" type="text/css" href="dist/css/jquery.dataTables.min.css"></script>">
<link rel="stylesheet" type="text/css" href="css/body.css">
<script src="assets/js/ie-emulation-modes-warning.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="assets/js/ie10-viewport-bug-workaround.js"></script>
<script src="dist/js/jquery-1.12.4.js"></script>
<script src="dist/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function () {
$('#otable').DataTable({
"searching": false,
"order" : [[ 5, "desc" ]]
});
$("#search").click(function(){
$("#searchPanelWrap").slideToggle("slow");
});
$("#searchServiceRequests").click(function(){
var filterVal ="";
filterVal = "srfno=" + $('#srf').val() + "&branch=" + $('#branch').val() + "&dept=" + $('#dept').val() + "&reqf=" + $('#datereqfrom').val() + "&reqt=" + $('#datereqto').val() + "";
document.location.href = 'servicereq.php?s=1&' + filterVal;
});
});
</script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<?php
include "header.php";
?>
</nav>
<br><br><br><br><br>
<div class="form">
<center>
<fieldset id="fieldsetform">
<div class="form"><br><br>
<center><h4>Service Request Forms</h4></center>
<ul class="tab-group"><br>
<a href="servicereq.php?s=0"><button style="width: 150px; height: 50px;" type="button" class="btn btn-success" value="Service">Service Request</button></a>
<a href="appreq.php"><button style="width: 150px; height: 50px;" type="button" class="btn btn-danger" value="Service">Close Request</button></a>
<button class="btn" style="width: 50px; height: 50px;" value="Search" id="search"><span class="glyphicon glyphicon-filter"></span></btn>
</ul>
<div id="searchPanelWrap" style="padding-bottom:10px; display:none;">
<input style = "text" placeholder = "SRF No." id="srf"/>
<input style = "text" placeholder = "Branch" id="branch"/>
<input style = "text" placeholder = "Department" id="dept"/>
Request Date From: <input style = "text" type = "date" value="" id="datereqfrom"/>
Request Date To: <input style = "text" type = "date" value="" id="datereqto"/>
<button class="btn btn-default" id="searchServiceRequests">Search</button>
</div>
<form action="downloadfile.php" method="get"></form>
<?php
//if(!$uname == 'uname' && !$pass = 'pass'){
include 'dbconn.php';
if($_SESSION['assign']!="Main Approver"){
$clause = "dept = '".$_SESSION['department']."' AND city='".$_SESSION['branch']."' AND type != '".$_SESSION['assign']."' AND status = 'PENDING' ";
}else{
$clause = "status = 'PENDING' ";
}
if($_GET["s"] == "1"){
$srf = $_GET["srfno"];
$branch = $_GET["branch"];
$dept = $_GET["dept"];
$datereqfrom = $_GET["reqf"];
$datereqto = $_GET["reqt"];
$srfFilter = "";
$brFilter = "";
$deptFilter = "";
$reqFilter = "";
if($srf != ""){
$srfFilter = "AND SRFNo = '".$srf."' ";
}
if($branch != ""){
$brFilter = "AND city = '".$branch."' ";
}
if($dept != ""){
$deptFilter = "AND dept = '".$dept."' ";
}
if($datereqfrom != "" && $datereqto != ""){
$reqFilter = "AND RequestDateTime BETWEEN '".$datereqfrom." 00:00:00.000' AND '".$datereqto." 23:59:59.999' ";
}
$addFilter = $srfFilter.$brFilter.$deptFilter.$reqFilter;
}else{
$addFilter = "";
}
$record= getAllServicePending($clause.$addFilter);
echo '<table id="otable" class="table table-striped">';
echo '<thead>';
echo '<th>SRF No.</th>';
echo '<th>Last Name</th>';
echo '<th>First Name</th>';
echo '<th>Branch</th>';
echo '<th>Department</th>';
echo '<th>Date Requested</th>';
echo '<th>Attached File</th>';
echo '<th>Service Form View</th>';
echo '<th>Status</th>';
echo '<th>Action</th>';
echo '</thead>';
echo "<tbody>";
foreach($record as $r){
$i=0;
echo '<tr>';
$idno;
foreach($r as $fields){
if($i==0) $idno=$fields;
//echo '<td>'.strtoupper($fields).'</td>';
$i++;
}
$files = $r['file'];
echo '<td>'.$r['SRFNo'].'</td>';
echo '<td>'.$r['lastreq'].'</td>';
echo '<td>'.$r['firstreq'].'</td>';
echo '<td>'.$r['city'].'</td>';
echo '<td>'.$r['dept'].'</td>';
echo '<td>'.$r['RequestDateTime'].'</td>';
echo '<td><a href="dlserv.php?filename='.$files.'">'.$r['file'].'</a></td>';
echo '<td><a href="serviceform.php?idno='.$idno.'">Service Request</a></td>';
echo '<td>'.$r['status'].'</td>';
echo '<td>
<button type="button" class="btn btn-success" onclick="window.location.href=`approveserv.php?idno='.$idno.'&status=approve`" style="width:136px;"><span class="glyphicon glyphicon-thumbs-up" style="padding-right:5px"></span>APPROVE</button><br>
<button type="button" class="btn btn-danger" onclick="window.location.href=`approveserv.php?idno='.$idno.'&status=disapprove`" style="width:136px;"><span class="glyphicon glyphicon-thumbs-down" style="padding-right:5px"></span>DISAPPROVE</button>
</td>';
echo '</tr>';
}
echo "</tbody>";
echo '</table>';
//}
?><br><br>
</div>
</fieldset>
</center>
</div><?php
include "footer.php";
?>
</body>
</html>
以下是我使用prompt()的方法,这只会执行SQL批准和拒绝,但提示的值不会存储到数据库中。
approveserv.php<?php
session_start();
if(!isset($_SESSION['user']) || !isset($_SESSION['lname']) || !isset($_SESSION['fname']) || !isset($_SESSION['lname']) || !isset($_SESSION['pass']) || !isset($_SESSION['assign']) || !isset($_SESSION['department']) || !isset($_SESSION['branch']) || !isset($_SESSION['province']) || !isset($_SESSION['position']))
{
header('Location:login.php');
}
include ('dbconn.php');
$idno = $_GET["idno"];
$reqstat = $_GET["status"];
$s = ret_status_service($idno);
$user = $_SESSION['user'];
$db = site_db();
if($reqstat=="approve"){
$sql = "UPDATE services SET status ='APPROVED', ApprovalDateTime = CURRENT_TIMESTAMP(), ApprovedBy = '".$user."' WHERE ser_id = ?";
}else{
$sql = "UPDATE services SET status ='DISAPPROVED', ApprovalDateTime = CURRENT_TIMESTAMP(), ApprovedBy = '".$user."' WHERE ser_id = ?";
}
$s = $db->prepare($sql);
$s->execute(array($idno));
$db = null;
echo "<script>if(prompt('Successfully ${reqstat}d request.')){document.location.href='servicereq.php?s=0'};</script>";
// header('location:servicereq.php');
?>
答案 0 :(得分:0)
如果您关注的是如何获得提示对话框的输入并将其发送到servicereq.php
。您可以参考以下代码:
//servicereq.php - to get the prompt message from approveserv.php and store it to database
if(isset($_REQUEST['prompt_msg'])){
$prompt_msg= $_REQUEST['prompt_msg'];
// you could continue to store it in the database
}
//approveserv.php - to output the javascript and get the prompt message and send it to servicereq.php
echo "<script>if(prompt_msg=prompt('Successfully ".$reqstat."d action request.')){document.location.href='servicereq.php?prompt_msg='+prompt_msg+'&s=0'};</script>";
注意:我想你可以设法将提示msg存储到数据库中,所以我没有在这里编写代码。
Here是如何使用提示的另一种材料。