Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building a Web Application with PHP and MariaDB: A Reference Guide

You're reading from   Building a Web Application with PHP and MariaDB: A Reference Guide Build fast, secure, and interactive web applications using this comprehensive guide

Arrow left icon
Product type Paperback
Published in Jun 2014
Publisher
ISBN-13 9781783981625
Length 200 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sai S Sriparasa Sai S Sriparasa
Author Profile Icon Sai S Sriparasa
Sai S Sriparasa
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. CRUD Operations, Sorting, Filtering, and Joins 2. Advanced Programming with MariaDB FREE CHAPTER 3. Advanced Programming with PHP 4. Setting Up Student Portal 5. Working with Files and Directories 6. Authentication and Access Control 7. Caching 8. REST API 9. Security 10. Performance Optimization Index

Adding a course


In this section, we will add the new Courses controller to our controllers' directory. Our Courses controller will extend the Base_Controller class and, upon instantiation, we will load the courses model (we are yet to create the model). The code snippet for the Courses controller will be similar to our Students controller; this is shown in the following code snippet; in the controllers/courses.php file:

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

  public function add(){

    if(isset($_POST['submit'])){
      unset($_POST['submit']);
      $this->view->id = $this->model->addCourse($_POST);
    }

    $this->view->render('courses/add');
  }
}

We will be using the add action to create a new course and add it to our courses table. In our add action, we are passing in the data in the $_POST superglobal over to the addCourse method provided by our courses...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime