我有请求表,其中包含显示表中所有记录的字段(id,name,date,department,answer)和(req_res1.php),我尝试创建多个登录名,仅为每个部门访问此表单。我的意思是在登录表单中有用户名和密码以及部门名称,当用户选择用户,传递和部门时,表单仅显示该部门的结果。我尝试了不同的东西,但没有任何作用。
req_res1.php
<?php
$connect = mysqli_connect('localhost', 'root', '', 'test')or die ( mysqli_error($connect) );
$sSQL= 'SET CHARACTER SET utf8';
mysqli_query($connect,$sSQL)
or die ('Can\'t charset in DataBase');
$query = "SELECT * FROM requests ORDER BY id DESC";
$result = mysqli_query($connect, $query);
?>
<html>
<head>
<title>update and delete records</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="jquery.tabledit.min.js"></script>
<style>
thead, tr {
color:black;
font-size: 14px;
font-weight: bold;
border-collapse: collapse;
border: 1.5px solid black;
}
th {
background-color: #66CCFF;
color: white;
border: 2px solid black;
}
</style>
</head>
<body dir="rtl">
<br />
<div id="header" align="center">
<img id="image1" src="img/egate4.png">
<br />
</div>
<div class="container" style="width:1200px;">
<br />
<div class="table-responsive">
<h3 align="center">requests display</h3><br />
<table id="editable_table" class="table table-bordered table-striped">
<thead>
<tr>
<th>request no</th>
<th>name</th>
<th>date of request</th>
<th>department</th>
<th>status</th>
</tr>
</thead>
<tbody>
<?php
while($row = mysqli_fetch_array($result))
{
echo '
<tr>
<td>'.$row["no"].'</td>
<td>'.$row["name"].'</td>
<td>'.$row["reqdate"].'</td>
<td>'.$row["dept"].'</td>
<td>'.$row["answer"].'</td>
</tr>
';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
$('#editable_table').Tabledit({
url:'req_res2.php',
columns:{
identifier:[0, "no"],
editable:[[1, 'name'], [2, 'reqdate'], [3, 'dept'],[4, 'answer']]
},
restoreButton:false,
onSuccess:function(data, textStatus, jqXHR)
{
if(data.req_res2 == 'delete')
{
$('#'+data.id).remove();
}
}
});
});
</script>
req_res2.php
<?php
header ('Content-Type: text/html; charset=UTF-8');
$connect = mysqli_connect('localhost', 'root', '', 'test')or die ( mysqli_error($connect) );
$sSQL= 'SET CHARACTER SET utf8';
mysqli_query($connect,$sSQL)
or die ('Can\'t charset in DataBase');
$input = filter_input_array(INPUT_POST);
$name = mysqli_real_escape_string($connect, $input["name"]);
$no = mysqli_real_escape_string($connect, $input["no"]);
$reqdate = mysqli_real_escape_string($connect, $input["reqdate"]);
$answer = mysqli_real_escape_string($connect, $input["answer"]);
if($input["action"] === 'edit')
{
$query = "
UPDATE requests
SET name = '".$name."',
answer = '".$answer."'
WHERE id = '".$input["id"]."'
";
mysqli_query($connect, $query);
}
if($input["action"] === 'delete')
{
$query = "
DELETE FROM requests
WHERE id = '".$input["id"]."'
";
mysqli_query($connect, $query);
}
echo json_encode($input);
?>