0

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 Answer 1

1

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

$course = $course_codeapp

it should have been

$course = $course_codeapp;
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for notice, but in my code i got put ";". maybe just now deleted. The problem still not solve
What is the datatype of coursecode? If it is a varchar you need to write it $sql="UPDATE tblstudent set course_code = '". mysql_real_escape_string($course) ."' WHERE id = ".mysql_real_escape_string($id);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.