当复选框选中但失败时,我正在尝试将我的 course_code 更新到我的数据库中。我试图从其他人那里修改,但似乎我犯了错误。谁能告诉我有什么问题?
这是我的assigncourse.php
<?php require_once("../includes/session.php"); ?>
<?php require_once("sessioncourse.php"); ?>
<?php $course_codefac = $_SESSION['course_code'] ; ?>
<?php confirm_logged_in(); ?>
<?php require_once("../includes/connection.php") ?>
<?php require_once("../includes/functions.php") ?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
function Change(id) {
$.ajax({
type: "GET",
url: "updateassigncourse.php",
data: {"id": id},
'success': function (response) {
console.log(response);
//TODO: use server response
}
});
};
</script>
<?php include("includes/header.php"); ?>
<div id="main">
<div class="full_w">
<?php
$querysel = "SELECT * FROM tblstudent ORDER BY student_id " ;
$resultsel = mysql_query($querysel, $connection);
echo "<h2><div class=\"h_title\">Please tick the student to join this
".$course_codefac." course</div></h2>";
echo "<table>";
echo "<thead>";
echo "<tr>";
echo "<th scope=\"col\">Matric ID</th>";
echo "<th scope=\"col\">Name</th>";
echo "<th scope=\"col\">Assign</th>";
echo "</tr>";
echo "</thead>";
while($rowsel = mysql_fetch_array($resultsel)){
if($rowsel['course_code'] == NULL){
$id = $rowsel['id'];
echo "<tr>";
echo "<tr>"."<td class=\"align-center\">".$rowsel['student_id']."
</td>";
echo "<td class=\"align-center\">".$rowsel['name']."</td>";
echo "<td class=\"align-center\">";
echo "<input type=\"checkbox\" onchange=\"javascript:
Change($id);\">";
echo "</td>";
}
}
echo "</table>";
?>
</div>
</div>
<?php include("includes/footer.php"); ?>
那么这是我的updateassigncourse.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'];
$course = $course_codeapp;
$sql="UPDATE tblstudent set course_code = ". mysql_real_escape_string($course)
." WHERE id = " .mysql_real_escape_string($id);
$result = mysql_query($sql);
?>