duanleiming2014 2013-05-12 12:32
浏览 30
已采纳

使用jquery使用复选框更新

I'm trying to update my course_code into my database when the checkbox checked but it fail. I tried to modify from others but seem like I make mistake. can anyone tell me what is the problem?

here is my 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"); ?>

then here is my 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条回答 默认 最新

  • dongmen1925 2013-05-12 12:38
    关注

    If this is your exact code, then there is a missing ';'

    $course = $course_codeapp
    

    it should have been

    $course = $course_codeapp;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题