I have a problem (I do not know how to do an UPDATE) when it comes to updating the student's file since it only changes the name and image of the student, and what I want to do is add or remove the courses in which it is enrolled from a multiple select.
This is a capture of the edit file:
Table Students
--------------------------------------------- - student_id - student_name - student_image - --------------------------------------------- - 1 - Ana - avatar.jpg - - 2 - David - avatar.jpg - - 3 - Jasmine - avatar.jpg - ---------------------------------------------
Table Courses
------------------------------------------- - course_id - course_title - course_image - ------------------------------------------- - 7 - Photoshop - image.jpg - - 8 - Cinema 4D - image.jpg - - 9 - Idesign - image.jpg - - 10 - Illustrator - image.jpg - -------------------------------------------
Table Students_Courses
---------------------------------------------- students_courses_id - course_id - student_id - ---------------------------------------------- - 1 - 7 - 1 - 2 - 8 - 2 - 3 - 9 - 2 - 4 - 10 - 3 - 5 - 8 - 1 ----------------------------------------------
My code
$connect = connect($database); if(!$connect){ header ('Location: ' . SITE_URL . '/controller/error.php'); }if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$course_id = $_POST['course_id']; $student_id = cleardata($_POST['student_id']); $student_name = cleardata($_POST['student_name']); $student_image_save = $_POST['student_image_save']; $student_image = $_FILES['student_image']; if (empty($student_image['name'])) { $student_image = $student_image_save; } else{ $student_image_upload = '../' . $items_config['images_folder'] . $_FILES['student_image']['name']; move_uploaded_file($_FILES['student_image']['tmp_name'], $student_image_upload); $student_image = $_FILES['student_image']['name']; }
$ statment = $ connect-> prepare ( 'UPDATE students SET student_name =: student_name, student_image =: student_image WHERE student_id =: student_id' ); $ statment-> execute (array ( ': student_name' = > $ student_name, ': student_image' = > $ student_image, ': student_id' = > $ student_id )); $ statment = $ connect-> prepare ('UPDATE students_courses SET course_id =: course_id WHERE student_id ='. $ student_id); $ statment-> execute ();