crud with php oop and mvc design pattern

Today, We want to share with you crud with php oop and mvc design pattern.In this post we will show you insert data using class and function in php, hear for add edit delete in php using oops we will give you demo and example for implement.In this post, we will learn about Simple CRUD example of MVC coding in PHP with an example.

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

crud with php oop and mvc design pattern

There are the Following The simple About CRUD with PHP MVC, PDO, JSON and Twitter Bootstrap Full Information With Example and source code.

As I will cover this Post with live Working example to develop The Model-View-Controller (MVC) Design Pattern for PHP, so the PHP OOP CRUD Tutorial – Step By Step is used for this example is following below.

A CRUD application in PHP with OOP & MVC

How to Create PHP CRUD using OOPS with MySQLi in MVC Example

crud_example.sql

-- phpMyAdmin SQL Dump
-- version 4.7.4
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Jan 23, 2019 at 06:34 PM
-- Server version: 5.6.37
-- PHP Version: 7.1.19

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `crud_example`
--

-- --------------------------------------------------------

--
-- Table structure for table `tbl_reporting`
--

CREATE TABLE `tbl_reporting` (
  `id` int(11) NOT NULL,
  `patient_id` int(11) NOT NULL,
  `existing` tinyint(4) NOT NULL,
  `invisible` tinyint(4) NOT NULL,
  `reporting_date` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `tbl_patient`
--

CREATE TABLE `tbl_patient` (
  `id` int(11) NOT NULL,
  `name` varchar(55) NOT NULL,
  `roll_number` int(11) NOT NULL,
  `dob` date NOT NULL,
  `class` varchar(55) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `tbl_reporting`
--
ALTER TABLE `tbl_reporting`
  ADD PRIMARY KEY (`id`),
  ADD KEY `patient_id` (`patient_id`);

--
-- Indexes for table `tbl_patient`
--
ALTER TABLE `tbl_patient`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `tbl_reporting`
--
ALTER TABLE `tbl_reporting`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=65;

--
-- AUTO_INCREMENT for table `tbl_patient`
--
ALTER TABLE `tbl_patient`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `tbl_reporting`
--
ALTER TABLE `tbl_reporting`
  ADD CONSTRAINT `tbl_reporting_ibfk_1` FOREIGN KEY (`patient_id`) REFERENCES `tbl_patient` (`id`);
COMMIT;

/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;
/*!40101 SET [email protected]_COLLATION_CONNECTION */;

index.php

<?php
require_once ("class/ConController.php");
require_once ("class/Patient.php");
require_once ("class/Reporting.php");

$db_handle = new ConController();

// $action = "";
if (! empty($_GET["action"])) {
    $action = $_GET["action"];
}
switch ($action) {
    case "reporting-add":
        if (isset($_POST['add'])) {
            $reporting = new Reporting();
            
            $reporting_timestamp = strtotime($_POST["reporting_date"]);
            $reporting_date = date("Y-m-d", $reporting_timestamp);
            
            if(!empty($_POST["patient_id"])) {
                $reporting->deleteReportingByDate($reporting_date);
                foreach($_POST["patient_id"] as $k=> $patient_id) {
                    $existing = 0;
                    $invisible = 0;
                    
                    if($_POST["reporting-$patient_id"] == "existing") {
                        $existing = 1;
                    }
                    else if($_POST["reporting-$patient_id"] == "invisible") {
                        $invisible = 1;
                    }
                    
                    $reporting->addReporting($reporting_date, $patient_id, $existing, $invisible);
                }
            }
            header("Location: index.php?action=reporting");
        }
        $patient = new Patient();
        $patientResult = $patient->getAllPatient();
        require_once "web/reporting-add.php";
        break;
    
    case "reporting-edit":
        $reporting_date = $_GET["date"];
        $reporting = new Reporting();
        if (isset($_POST['add'])) {
            $reporting->deleteReportingByDate($reporting_date);
            if(!empty($_POST["patient_id"])) {
                foreach($_POST["patient_id"] as $k=> $patient_id) {
                    $existing = 0;
                    $invisible = 0;
                    
                    if($_POST["reporting-$patient_id"] == "existing") {
                        $existing = 1;
                    }
                    else if($_POST["reporting-$patient_id"] == "invisible") {
                        $invisible = 1;
                    }
                    
                    $reporting->addReporting($reporting_date, $patient_id, $existing, $invisible);
                }
            }
            header("Location: index.php?action=reporting");
        }
        
        $output = $reporting->getReportingByDate($reporting_date);
        
        $patient = new Patient();
        $patientResult = $patient->getAllPatient();
        require_once "web/reporting-edit.php";
        break;
    
    case "reporting-delete":
        $reporting_date = $_GET["date"];
        $reporting = new Reporting();
        $reporting->deleteReportingByDate($reporting_date);
        
        $output = $reporting->getReporting();
        require_once "web/reporting.php";
        break;
    
    case "reporting":
        $reporting = new Reporting();
        $output = $reporting->getReporting();
        require_once "web/reporting.php";
        break;
    
    case "patient-add":
        if (isset($_POST['add'])) {
            $name = $_POST['name'];
            $roll_number = $_POST['roll_number'];
            $dob = "";
            if ($_POST["dob"]) {
                $dob_timestamp = strtotime($_POST["dob"]);
                $dob = date("Y-m-d", $dob_timestamp);
            }
            $class = $_POST['class'];
            
            $patient = new Patient();
            $insertId = $patient->addPatient($name, $roll_number, $dob, $class);
            if (empty($insertId)) {
                $response = array(
                    "message" => "Problem in Adding New Record",
                    "type" => "error"
                );
            } else {
                header("Location: index.php");
            }
        }
        require_once "web/patient-add.php";
        break;
    
    case "patient-edit":
        $patient_id = $_GET["id"];
        $patient = new Patient();
        
        if (isset($_POST['add'])) {
            $name = $_POST['name'];
            $roll_number = $_POST['roll_number'];
            $dob = "";
            if ($_POST["dob"]) {
                $dob_timestamp = strtotime($_POST["dob"]);
                $dob = date("Y-m-d", $dob_timestamp);
            }
            $class = $_POST['class'];
            
            $patient->editPatient($name, $roll_number, $dob, $class, $patient_id);
            
            header("Location: index.php");
        }
        
        $output = $patient->getPatientById($patient_id);
        require_once "web/patient-edit.php";
        break;
    
    case "patient-delete":
        $patient_id = $_GET["id"];
        $patient = new Patient();
        
        $patient->deletePatient($patient_id);
        
        $output = $patient->getAllPatient();
        require_once "web/patient.php";
        break;
    
    default:
        $patient = new Patient();
        $output = $patient->getAllPatient();
        require_once "web/patient.php";
        break;
}
?>

class/Reporting.php

<?php 
require_once ("class/ConController.php");
class Reporting {
    private $db_handle;
    
    function __construct() {
        $this->db_handle = new ConController();
    }
    
    function addReporting($reporting_date, $patient_id, $existing, $invisible) {
        $query = "INSERT INTO tbl_reporting (reporting_date,patient_id,existing,invisible) VALUES (?, ?, ?, ?)";
        $paramType = "siii";
        $paramValue = array(
            $reporting_date,
            $patient_id,
            $existing,
            $invisible
        );
        
        $insertId = $this->db_handle->insert($query, $paramType, $paramValue);
        return $insertId;
    }
    
    function deleteReportingByDate($reporting_date) {
        $query = "DELETE FROM tbl_reporting WHERE reporting_date = ?";
        $paramType = "s";
        $paramValue = array(
            $reporting_date
        );
        $this->db_handle->update($query, $paramType, $paramValue);
    }
    
    function getReportingByDate($reporting_date) {
        $query = "SELECT * FROM tbl_reporting LEFT JOIN tbl_patient ON tbl_reporting.patient_id = tbl_patient.id WHERE reporting_date = ? ORDER By patient_id";
        $paramType = "s";
        $paramValue = array(
            $reporting_date
        );
        
        $output = $this->db_handle->runQuery($query, $paramType, $paramValue);
        return $output;
    }
    
    function getReporting() {
        $sql = "SELECT id, reporting_date, sum(existing) as existing, sum(invisible) as invisible FROM tbl_reporting GROUP By reporting_date";
        $output = $this->db_handle->runBaseQuery($sql);
        return $output;
    }
}
?>

class/ConController.php

<?php
class ConController {
    private $host = "localhost";
    private $user = "root";
    private $password = "test";
    private $database = "crud_example";
    private $conn;
    
    function __construct() {
        $this->conn = $this->connectDB();
    }   
    
    function connectDB() {
        $conn = mysqli_connect($this->host,$this->user,$this->password,$this->database);
        return $conn;
    }
    
    function runBaseQuery($query) {
        $output = $this->conn->query($query);   
        if ($output->num_rows > 0) {
            while($row = $output->fetch_assoc()) {
                $outputset[] = $row;
            }
        }
        return $outputset;
    }
    
    
    
    function runQuery($query, $param_type, $param_value_array) {
        $sql = $this->conn->prepare($query);
        $this->bindQueryParams($sql, $param_type, $param_value_array);
        $sql->execute();
        $output = $sql->get_output();
        
        if ($output->num_rows > 0) {
            while($row = $output->fetch_assoc()) {
                $outputset[] = $row;
            }
        }
        
        if(!empty($outputset)) {
            return $outputset;
        }
    }
    
    function bindQueryParams($sql, $param_type, $param_value_array) {
        $param_value_reference[] = & $param_type;
        for($i=0; $i<count($param_value_array); $i++) {
            $param_value_reference[] = & $param_value_array[$i];
        }
        call_user_func_array(array(
            $sql,
            'bind_param'
        ), $param_value_reference);
    }
    
    function insert($query, $param_type, $param_value_array) {
        $sql = $this->conn->prepare($query);
        $this->bindQueryParams($sql, $param_type, $param_value_array);
        $sql->execute();
        $insertId = $sql->insert_id;
        return $insertId;
    }
    
    function update($query, $param_type, $param_value_array) {
        $sql = $this->conn->prepare($query);
        $this->bindQueryParams($sql, $param_type, $param_value_array);
        $sql->execute();
    }
}
?>

class/Patient.php

<?php 
require_once ("class/ConController.php");
class Patient
{
    private $db_handle;
    
    function __construct() {
        $this->db_handle = new ConController();
    }
    
    function addPatient($name, $roll_number, $dob, $class) {
        $query = "INSERT INTO tbl_patient (name,roll_number,dob,class) VALUES (?, ?, ?, ?)";
        $paramType = "siss";
        $paramValue = array(
            $name,
            $roll_number,
            $dob,
            $class
        );
        
        $insertId = $this->db_handle->insert($query, $paramType, $paramValue);
        return $insertId;
    }
    
    function editPatient($name, $roll_number, $dob, $class, $patient_id) {
        $query = "UPDATE tbl_patient SET name = ?,roll_number = ?,dob = ?,class = ? WHERE id = ?";
        $paramType = "sissi";
        $paramValue = array(
            $name,
            $roll_number,
            $dob,
            $class,
            $patient_id
        );
        
        $this->db_handle->update($query, $paramType, $paramValue);
    }
    
    function deletePatient($patient_id) {
        $query = "DELETE FROM tbl_patient WHERE id = ?";
        $paramType = "i";
        $paramValue = array(
            $patient_id
        );
        $this->db_handle->update($query, $paramType, $paramValue);
    }
    
    function getPatientById($patient_id) {
        $query = "SELECT * FROM tbl_patient WHERE id = ?";
        $paramType = "i";
        $paramValue = array(
            $patient_id
        );
        
        $output = $this->db_handle->runQuery($query, $paramType, $paramValue);
        return $output;
    }
    
    function getAllPatient() {
        $sql = "SELECT * FROM tbl_patient ORDER BY id";
        $output = $this->db_handle->runBaseQuery($sql);
        return $output;
    }
}
?>

web/reporting.php

<?php require_once "web/header.php"; ?>
    <div style="text-align: right; margin: 20px 0px 10px;">
        <a id="btnAddAction" href="index.php?action=reporting-add"><img src="web/image/icon-add.png" />Add Reporting</a>
    </div>
    <div id="drags-grid">
        <table cellpadding="10" cellspacing="1" class="reporting_table">
            <thead>
                <tr>
                    <th><strong>Date</strong></th>
                    <th><strong>Present</strong></th>
                    <th><strong>Absent</strong></th>
                    <th><strong>Action</strong></th>

                </tr>
            </thead>
            <tbody>
                    <?php
                    if (! empty($output)) {
                        foreach ($output as $k => $v) {
                            ?>
          <tr>
                    <td><?php 
                    $reporting_date = "";
                    if(!empty($output[$k]["reporting_date"])) {
                        $reporting_timestamp = strtotime($output[$k]["reporting_date"]);
                        $reporting_date = date("m-d-Y", $reporting_timestamp);
                    }
                    echo $reporting_date; ?></td>
                    <td><?php echo $output[$k]["existing"]; ?></td>
                    <td><?php echo $output[$k]["invisible"]; ?></td>
                    <td><a class="btnEditAction"
                        href="index.php?action=reporting-edit&date=<?php echo $output[$k]["reporting_date"]; ?>">
                        <img src="web/image/icon-edit.png" />
                        </a>
                        <a class="btnDeleteAction" 
                        href="index.php?action=reporting-delete&date=<?php echo $output[$k]["reporting_date"]; ?>">
                        <img src="web/image/icon-delete.png" />
                        </a>
                    </td>
                </tr>
                    <?php
                        }
                    }
                    ?>
                
            
            
            <tbody>
        
        </table>
    </div>
</body>
</html>

web/reporting-add.php

<?php require_once "web/header.php"; ?>

<form name="patiantFrmAdded" method="post" action="" id="patiantFrmAdded"
    onSubmit="return validate();">
    <div>
        <input type="date" name="reporting_date" id="reporting_date" class="patientInfoCart"> <span id="reporting_date-info" class="info"></span>
    </div>
    <div id="drags-grid">
        <table cellpadding="10" cellspacing="1">
            <thead>
                <tr>
                    <th><strong>Patient</strong></th>
                    <th><strong>Present</strong></th>
                    <th><strong>Absent</strong></th>

                </tr>
            </thead>
            <tbody>
                    <?php 
            if (! empty($patientResult)) {
                foreach ($patientResult as $k => $v) {
            ?>
          <tr>
                    <td><input type="hidden"
            name="patient_id[]" id="patient_id" value = "<?php echo $patientResult[$k]["id"]; ?>">
            <?php echo $patientResult[$k]["name"]; ?></td>
                    <td><input type="radio" name="reporting-<?php echo $patientResult[$k]["id"]; ?>" value="existing" checked /></td>
                    <td><input type="radio" name="reporting-<?php echo $patientResult[$k]["id"]; ?>" value="invisible" /></td>
                </tr>
                    <?php
                        }
                    }
                    ?>
            <tbody>
        
        </table>
        
    </div>
   <div>
        <input type="submit" name="add" id="btnSubmit" value="Add" />
    </div> 
</form>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"
    type="text/javascript"></script>
<script>
function validate() {
    var valid = true;   
    $(".patientInfoCart").css('background-color','');
    $(".info").html('');
    
    if(!$("#reporting_date").val()) {
        $("#reporting_date-info").html("(required)");
        $("#reporting_date").css('background-color','#FFFFDF');
        valid = false;
    } 
    return valid;
}
</script>
</body>
</html>

web/reporting-edit.php

<?php require_once "web/header.php"; ?>

<form name="patiantFrmAdded" method="post" action="" id="patiantFrmAdded"
    onSubmit="return validate();">
    <div>
    <?php 
        $reporting_timestamp = strtotime($reporting_date);
        $reporting_date = date("m-d-Y", $reporting_timestamp);
    ?>
        <input name="reporting_date" id="reporting_date" class="patientInfoCart" disabled value="<?php echo $reporting_date; ?>"> 
    </div>
    <div id="drags-grid">
        <table cellpadding="10" cellspacing="1">
            <thead>
                <tr>
                    <th><strong>Patient</strong></th>
                    <th><strong>Present</strong></th>
                    <th><strong>Absent</strong></th>

                </tr>
            </thead>
            <tbody>
                    <?php 
            if (! empty($patientResult)) {
                foreach ($patientResult as $k => $v) {
                    $existingChecked = "";
                    $invisibleChecked = "";
                    
                    if($patientResult[$k]["id"] == $output[$k]["patient_id"]) {
                        if($output[$k]["existing"] == 1) { 
                            $existingChecked = "checked";
                        } else if($output[$k]["invisible"] == 1) { 
                            $invisibleChecked = "checked";
                        }
                    }
            ?>
          <tr>
                    <td><input type="hidden"
            name="patient_id[]" id="patient_id" value = "<?php echo $patientResult[$k]["id"]; ?>">
            <?php echo $patientResult[$k]["name"]; ?></td>
                    <td><input type="radio" name="reporting-<?php echo $patientResult[$k]["id"]; ?>" value="existing" <?php echo $existingChecked; ?> /></td>
                    <td><input type="radio" name="reporting-<?php echo $patientResult[$k]["id"]; ?>" value="invisible" <?php echo $invisibleChecked; ?> /></td>
                </tr>
                    <?php
                        }
                    }
                    ?>
            <tbody>
        
        </table>
        
    </div>
   <div>
        <input type="submit" name="add" id="btnSubmit" value="Save" />
    </div> 
</form>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"
    type="text/javascript"></script>
<script>
function validate() {
    var valid = true;   
    $(".patientInfoCart").css('background-color','');
    $(".info").html('');
    
    if(!$("#reporting_date").val()) {
        $("#reporting_date-info").html("(required)");
        $("#reporting_date").css('background-color','#FFFFDF');
        valid = false;
    } 
    return valid;
}
</script>
</body>
</html>

web/header.php

<html>
<head>
<title>How to Create PHP Crud using OOPS and MySQLi</title>
<link href="web/css/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
    <h2>How to Create PHP Crud using OOPS and MySQLi</h2>
    <div>
        <ul class="menu-list">
            <li><a href="index.php">Patient</a></li>
            <li><a href="index.php?action=reporting">Reporting</a></li>
        </ul>
    </div>

web/patient.php

<?php require_once "web/header.php"; ?>
    <div style="text-align: right; margin: 20px 0px 10px;">
        <a id="btnAddAction" href="index.php?action=patient-add"><img src="web/image/icon-add.png" />Add Patient</a>
    </div>
    <div id="drags-grid">
        <table cellpadding="10" cellspacing="1">
            <thead>
                <tr>
                    <th><strong>Patient Name</strong></th>
                    <th><strong>Roll Number</strong></th>
                    <th><strong>Date of Birth</strong></th>
                    <th><strong>Class</strong></th>
                    <th><strong>Action</strong></th>

                </tr>
            </thead>
            <tbody>
                    <?php
                    if (! empty($output)) {
                        foreach ($output as $k => $v) {
                            ?>
          <tr>
                    <td><?php echo $output[$k]["name"]; ?></td>
                    <td><?php echo $output[$k]["roll_number"]; ?></td>
                    <td><?php echo $output[$k]["dob"]; ?></td>
                    <td><?php echo $output[$k]["class"]; ?></td>
                    <td><a class="btnEditAction"
                        href="index.php?action=patient-edit&id=<?php echo $output[$k]["id"]; ?>">
                        <img src="web/image/icon-edit.png" />
                        </a>
                        <a class="btnDeleteAction" 
                        href="index.php?action=patient-delete&id=<?php echo $output[$k]["id"]; ?>">
                        <img src="web/image/icon-delete.png" />
                        </a>
                    </td>
                </tr>
                    <?php
                        }
                    }
                    ?>
                
            
            
            <tbody>
        
        </table>
    </div>
</body>
</html>

web/patient-add.php

<?php require_once "web/header.php"; ?>

<form name="patiantFrmAdded" method="post" action="" id="patiantFrmAdded"
    onSubmit="return validate();">
    <div id="mail-status"></div>
    <div>
        <label style="padding-top: 20px;">Name</label> <span
            id="name-info" class="info"></span><br /> <input type="text"
            name="name" id="name" class="patientInfoCart">
    </div>
    <div>
        <label>Roll Number</label> <span id="roll-number-info"
            class="info"></span><br /> <input type="text"
            name="roll_number" id="roll_number" class="patientInfoCart">
    </div>
    <div>
        <label>Date of Birth</label> <span id="dob-info" class="info"></span><br />
        <input type="date" name="dob" id="dob" class="patientInfoCart">
    </div>
    <div>
        <label>Class</label> <span id="class-info" class="info"></span><br />
        <input type="text" name="class" id="class" class="patientInfoCart">
    </div>
    <div>
        <input type="submit" name="add" id="btnSubmit" value="Add" />
    </div>
    </div>
</form>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"
    type="text/javascript"></script>
<script>
function validate() {
    var valid = true;   
    $(".patientInfoCart").css('background-color','');
    $(".info").html('');
    
    if(!$("#name").val()) {
        $("#name-info").html("(required)");
        $("#name").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#roll_number").val()) {
        $("#roll-number-info").html("(required)");
        $("#roll_number").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#dob").val()) {
        $("#dob-info").html("(required)");
        $("#dob").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#class").val()) {
        $("#class-info").html("(required)");
        $("#class").css('background-color','#FFFFDF');
        valid = false;
    }   
    return valid;
}
</script>
</body>
</html>

web/patient-edit.php

<?php require_once "web/header.php"; ?>

<form name="patiantFrmAdded" method="post" action="" id="patiantFrmAdded"
    onSubmit="return validate();">
    <div id="mail-status"></div>
    <div>
        <label style="padding-top: 20px;">Name</label> <span
            id="name-info" class="info"></span><br /> <input type="text"
            name="name" id="name" class="patientInfoCart"
            value="<?php echo $output[0]["name"]; ?>">
    </div>
    <div>
        <label>Roll Number</label> <span id="roll-number-info"
            class="info"></span><br /> <input type="text"
            name="roll_number" id="roll_number" class="patientInfoCart"
            value="<?php echo $output[0]["roll_number"]; ?>">
    </div>
    <div>
        <label>Date of Birth</label> <span id="dob-info" class="info"></span><br />
        <input type="text" name="dob" id="dob" class="patientInfoCart"
            value="<?php echo $output[0]["dob"]; ?>">
    </div>
    <div>
        <label>Class</label> <span id="class-info" class="info"></span><br />
        <input type="text" name="class" id="class" class="patientInfoCart"
            value="<?php echo $output[0]["class"]; ?>">
    </div>
    <div>
        <input type="submit" name="add" id="btnSubmit" value="Save" />
    </div>
    </div>
    <script src="https://code.jquery.com/jquery-2.1.1.min.js"
        type="text/javascript"></script>
    <script>
function validate() {
    var valid = true;   
    $(".patientInfoCart").css('background-color','');
    $(".info").html('');
    
    if(!$("#name").val()) {
        $("#name-info").html("(required)");
        $("#name").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#roll_number").val()) {
        $("#roll-number-info").html("(required)");
        $("#roll_number").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#dob").val()) {
        $("#dob-info").html("(required)");
        $("#dob").css('background-color','#FFFFDF');
        valid = false;
    }
    if(!$("#class").val()) {
        $("#class-info").html("(required)");
        $("#class").css('background-color','#FFFFDF');
        valid = false;
    }   
    return valid;
}
</script>
    </body>
    </html>

css/style.css

body {
    width: 610px;
    font-family: Arial;
    color: #212121;
}

#drags-grid {
    margin-bottom: 30px;
}

#drags-grid .txt-heading {
    background-color: #D3F5B8;
}

#drags-grid table {
    width: 100%;
    background-color: #F0F0F0;
}

#drags-grid table td {
    background-color: #FFFFFF;
}

.patientInfoCart {
    padding: 10px;
    border: #E0E0E0 1px solid;
    border-radius: 3px;
    width: 250px;
    margin: 5px 0px 10px 0px;
}

.btnEditAction {
    cursor: pointer;
    text-decoration: none;
    margin-right: 10px;
}

.btnDeleteAction {
    cursor: pointer;
}

#btnAddAction {
    padding: 6px 20px;
    color: #212121;
    text-decoration: none;
    border-radius: 3px;
    cursor: pointer;
    border: #212121 1px solid;
    margin-bottom: 10px;
    display: inline-block;
}

#btnAddAction img {
    margin-right: 5px;
    vertical-align: middle;
}

#patiantFrmAdded {
    border: #E0E0E0 1px solid;
    padding: 10px 20px 20px 20px;
    border-radius: 3px;
}

#patiantFrmAdded div {
    margin-bottom: 15px;
}

#patiantFrmAdded div label {
    margin-left: 5px;
}

.error {
    background-color: #FF6600;
    border: #AA4502 1px solid;
    padding: 5px 10px;
    color: #FFFFFF;
    border-radius: 4px;
}

.info {
    font-size: .8em;
    color: #FF6600;
    letter-spacing: 2px;
    padding-left: 5px;
}

ul.menu-list {
    list-style: none;
    margin: 0px 0px 40px 0px;
    padding: 0px;
    background: #E0E0E0;
    border-radius: 3px;
}

ul.menu-list li{
    display: inline-block;
    padding: 10px 20px;
}

ul.menu-list li a{
    color: #212121;
    text-decoration: none;
}

ul.menu-list li a:hover{
    text-decoration: underline;
}

#btnSubmit {
    padding: 8px;
    background: #09F;
    border: #048eec 1px solid;
    color: #FFF;
    font-size: 0.9em;
    border-radius: 3px;
    width: 150px;
}
.reporting_table td {
    text-align: center;
}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about The Model-View-Controller (MVC) Design Pattern for PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to Open URL in New Tab using Drupal
  2.   How to get last inserted id in Laravel
  3.   Display Uploaded Image Using Javascript Example
  4.   How to Create AngularJS UI-Grid Editable - GridView
  5.   how to loop through an array of objects in javascript?
  6.   Simple Ecommerce PHP Shopping Cart Application
  7.   PHP nested While Loops and Multiple Conditions
  8.   Material Design Add icons in Select options
  9.   jQuery Ajax File upload with Percentage Progress bar using PHP MySQLi
  10.   Reusable PHP CRUD DATABASE FUNCTIONS