抱歉没有说明我的问题。其实我想更新我在数据库中的数据。但现在的问题是即使我尝试选择批准或拒绝 ajax 仍然不会更新。我是 ajax 新手并尝试在网络上搜索,但我的代码仍然有问题
这是我的 php 页面
<?php
$querysel = "SELECT * FROM tblinternapplication WHERE course_code = '{$course_codeapp}' ORDER BY student_id, 1 DESC " ;
$resultsel = mysql_query($querysel, $connection);
echo "<h2><div class=\"h_title\">Status still in pending</div></h2>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th scope=\"col\">Matric ID</th>";
echo "<th scope=\"col\">Company name</th>";
echo "<th scope=\"col\" width = \"200\">Job Scope</th>";
echo "<th scope=\"col\">Status</th>";
echo "<th scope=\"col\">Action</th>";
echo "</tr>";
echo "</thead>";
while($rowsel = mysql_fetch_array($resultsel)){
if($rowsel['status_approval'] == NULL){
$id = $rowsel['id'];
echo "<tr>";
echo "<tr>"."<td class=\"align-center\">".$rowsel['student_id']."</td>";
echo "<td class=\"align-center\">".$rowsel['company_name']."</td>";
echo "<td class=\"align-center\" width = \"200\">".$rowsel['job_scope']."</td>";
echo "<td class=\"align-center\">";
if($rowsel['status_approval'] != NULL){
if( $rowsel['status_approval'] == 0)
{
echo "Reject";
}
else
{
echo "Approve";
}
}
else
{ echo "Pending";
}
echo "</td>";
echo "<td class=\"align-center\"><select name=\"approve\"
onchange=\"getstatus(this.value)\">";
echo "<option value=\"\">Select status:</option>";
echo "<option value=\"1\">Approve</option>";
echo "<option value=\"0\">Reject</option>";
echo "</select>";
echo "</td>";
echo "</tr>";
}
}
echo "</table>";
这是我的 jscript 页面
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
function getstatus(id, approve)
{
if (approve=="")
{
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","updatestatus.php?id=" + id + "&status=" + approve,true);
xmlhttp.send();
}
</script>
那么这是我的updatestatus.php
<?php require_once("../includes/session.php"); ?>
<?php require_once("sessioncourse.php"); ?>
<?php $course_codeapp = $_SESSION['course_code'] ; ?>
<?php confirm_logged_in(); ?>
<?php require_once("../includes/connection.php") ?>
<?php require_once("../includes/functions.php") ?>
<?php
$id = $_GET['id'];
$status =$_GET['status'];
$sql="UPDATE tblinternapplication set status_approval = $status WHERE id = $id ";
$result = mysql_query($sql);
?>
我工作了几天,但问题仍然无法解决。希望可以有人帮帮我。我会感谢你的帮助!