gpt4 book ai didi

php - 更改后不显示新数据

转载 作者:可可西里 更新时间:2023-11-01 08:16:19 25 4
gpt4 key购买 nike

我为我的网页创建了一个搜索功能,以便它可以更新信息。当我搜索记录并更新信息时。然后返回搜索记录再次显示原始信息。我检查了 MySQL 数据库,它确实显示信息发生了变化,但不确定为什么会发生这种情况。以前有人遇到过这个问题吗?

这是我的 index.php 表单

<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">

<title></title>
<meta content="IE=9" http-equiv="X-UA-Compatible">
<link href="css/style01.css" rel="stylesheet"><!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
<h2 style="text-align: center">Inventory Integrity Edit Request
Form</h2><br>
<br>

<div class="wrapper">
<div class="mainContent">
<form class="form-horizontal" method="get">
<div class="form-group">
<br>
<br>
<label class="col-sm-2 control-label" for="id">Enter
Request ID #</label>

<div class="input-group col-sm-9">
<input class="form-control" id="id" name="=id"
placeholder="Type the id" type="text"> <span class=
"input-group-btn"><button class=
"btn btn-default btnSearch" type="button"><span class=
"input-group-btn"><span class=
"input-group-btn"><span class=
"input-group-btn"><span class=
"input-group-btn"><span class=
"input-group-btn"><span class=
"glyphicon glyphicon-search">Search</span></span></span></span></span></span></button></span>
</div>
</div>
</form>

<div class="col-sm-2"></div>

<div class="col-sm-9">
<!-- This table is where the data is display. -->

<table class="table table-striped table-hover" id=
"resultTable">
<thead>
<tr>
<th>Id</th>

<th>Name</th>

<th>lanId</th>

<th>Department</th>

<th>Manager</th>

<th>Work Requested</th>

<th>PO</th>

<th>IS</th>

<th>Request Comments</th>
</tr>
</thead>

<tbody></tbody>
</table>
</div>
</div>
</div><!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="js/jquery-1.10.2.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script> <script type="text/javascript">
jQuery(document).ready(function($) {
$('.btnSearch').click(function(){
makeAjaxRequest();
});

$('form').submit(function(e){
e.preventDefault();
makeAjaxRequest();
return false;
});

function makeAjaxRequest() {
$.ajax({
url: 'php/search.php',
type: 'get',
data: {id: $('input#id').val()},
success: function(response) {
$('table#resultTable tbody').html(response);
}
});
}
});
</script>
</body>
</html>

这是我的 search.php 表单

<?php

require_once 'db_connect.php';
$conn = dbConnect();
$OK = true; // We use this to verify the status of the update.
if (isset($_GET['id'])) {
// Create the query
$data = "%".$_GET['id']."%";
$sql = 'SELECT * FROM requests WHERE id like ?';
$stmt = $conn->prepare($sql);
$results = $stmt->execute(array($data));
$rows = $stmt->fetchAll();
$error = $stmt->errorInfo();
//echo $error[2];
}
// If there are no records.
if(empty($rows)) {
echo "<tr>";
echo "<td colspan='4'>There were not records</td>";
echo "</tr>";
}
else {
foreach ($rows as $row) {
echo "<tr>";
$id = $row['id'];
echo "<td><a href='update.php?id=$id'>$id</a></td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['lanId']."</td>";
echo "<td>".$row['department']."</td>";
echo "<td>".$row['mgrname']."</td>";
echo "<td>".$row['work_requested']."</td>";
echo "<td>".$row['purchase_order']."</td>";
echo "<td>".$row['inbound_shipment']."</td>";
echo "<td>".$row['request_comments']."</td>";


echo "</tr>";
}
}
?>

最佳答案

禁用ajax缓存:

$.ajax({
url: 'php/search.php',
cache: false,
type: 'get',
data: {
id: $('input#id').val()
},
success: function (response) {
$('table#resultTable tbody').html(response);
}
});


编辑:来自 jQuery.ajax()jQuery API 文档:

cache (default: true, false for dataType 'script' and 'jsonp')

关于php - 更改后不显示新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27000447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com