private function _map_posted_data()
 {
     $student = new Student();
     $student->set_first_name($_POST['first_name']);
     $student->set_last_name($_POST['last_name']);
     $student->set_dob($_POST['dob']);
     $student->set_blood_group($_POST['blood_group']);
     $student->set_email($_POST['email']);
     $student->set_contact($_POST['contact']);
     $student->set_program_id($_POST['program_id']);
     return $student;
 }
 public function get_all()
 {
     $student_list = array();
     $this->db->connect();
     $sql = "SELECT * from tbl_student";
     $result = $this->db->fetchQuery($sql);
     if ($result->num_rows > 0) {
         while ($row = $result->fetch_assoc()) {
             $student = new Student();
             $student->set_id($row['id']);
             $student->set_first_name($row['first_name']);
             $student->set_last_name($row['last_name']);
             $student->set_dob($row['dob']);
             $student->set_blood_group($row['blood_group']);
             $student->set_email($row['email']);
             $student->set_contact($row['contact']);
             $student->set_program_id($row['program_id']);
             array_push($student_list, $student);
         }
     }
     $this->db->close();
     return $student_list;
 }
 public function get_by_id($id)
 {
     $student = null;
     $this->db->connect();
     $sql = "SELECT id,first_name,last_name,dob,blood_group,email,contact,program_id from tbl_student WHERE id=?";
     $stmt = $this->db->initStatement($sql);
     $stmt->bind_param("i", $id);
     $stmt->execute();
     $stmt->bind_result($id, $first_name, $last_name, $dob, $blood_group, $email, $contact, $program_id);
     while ($stmt->fetch()) {
         $student = new Student();
         $student->set_id($id);
         $student->set_first_name($first_name);
         $student->set_last_name($last_name);
         $student->set_dob($dob);
         $student->set_blood_group($blood_group);
         $student->set_email($email);
         $student->set_contact($contact);
         $student->set_program_id($program_id);
     }
     $this->db->close();
     return $student;
 }
Beispiel #4
0
<?php

include_once '../config.php';
include_once ROOT_PATH . 'system/models/student.class.php';
include_once ROOT_PATH . 'system/repository/student_repository.class.php';
include_once 'header.php';
if (!isset($_POST['submit'])) {
    header('location:student.php?error=nopage');
}
$student = new Student();
$student->set_first_name($_POST['first_name']);
$student->set_last_name($_POST['last_name']);
$student->set_dob($_POST['dob']);
$student->set_blood_group($_POST['blood_group']);
$student->set_email($_POST['email']);
$student->set_contact($_POST['contact']);
$student->set_program_id($_POST['program_id']);
$student_repository = new StudentRepository();
$result_add = 0;
$result_edit = 0;
if (!isset($_POST['id']) || $_POST['id'] == '') {
    $result_add = $student_repository->insert($student);
} else {
    $student->set_id($_POST['id']);
    $result_edit = $student_repository->update($student);
}
if ($result_add > 0) {
    header('location:student.php?success=true');
} elseif ($result_edit > 0) {
    header('location:student.php?update=true');
} elseif ($result_edit == 0) {