Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By : Sai S Sriparasa
Book Image

Building a Web Application with PHP and MariaDB: A Reference Guide

By: Sai S Sriparasa

Overview of this book

Table of Contents (17 chapters)
Building a Web Application with PHP and MariaDB: A Reference Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Registering a student to a course


In this section, we will register a student for a course. We will allow the users to register a student to a course by accepting the student ID and course ID. We will add the new StudentsCourses controller to our controllers directory and it will extend the Base_Controller class. Upon instantiation, we will load the StudentCourses model (similar to other controllers in the application) in the controllers/studentsCourses.php file:

<?php
class StudentsCourses extends Base_Controller{
  public function __construct(){
    parent::__construct();
    $this->loadModel("studentsCourses");
  }

  public function register(){

    if(isset($_POST['submit'])){
      unset($_POST['submit']);
      $student_id = $_POST['student_id'];
      $course_id = $_POST['course_id'];
      $this->view->id = $this->model->registerStudentCourse($student_id, $course_id);
    }
    $this->view->render('studentsCourses/register');
  }
}

We will be using the register...