使用jquery使用复选框更新

时间:2013-05-12 12:32:14

标签: php jquery ajax

当我选中复选框时,我正在尝试将我的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);

?>

1 个答案:

答案 0 :(得分:1)

如果这是您的确切代码,则缺少';'

$course = $course_codeapp

应该是

$course = $course_codeapp;