PHP Classes

File: crud_example.php

Recommend this page to a friend!
  Classes of Muhammad Mahbubur Rahman   PHP Simple CRUD with MySQL   crud_example.php   Download  
File: crud_example.php
Role: Example script
Content type: text/plain
Description: Simple example to use the class
Class: PHP Simple CRUD with MySQL
Generate SQL and forms to perform CRUD operations
Author: By
Last change:
Date: 8 years ago
Size: 839 bytes
 

Contents

Class file image Download
<?php
include("crudClass.php");

$con = $crud->db_con('localhost','root','mysql','crud');// Connect Database

$crud = new crudClass('kitchen','instrument,code,type');// Initiate the class with table information

if($_POST['submit']){
   
$create_sql = $crud->create();//Fetch INSERT query
   
mysqli_query($con,$create_sql);
}
if(
$_POST['update']){
   
$update_sql = $crud->update($_POST['id']);//Fetch UPDATE query
   
mysqli_query($con,$update_sql);
}
if(
$_POST['delete']){
   
$delete_sql = $crud->delete($_POST['id']);//Fetch DELETE query
   
mysqli_query($con,$delete_sql);
}

echo
$crud->create_form();//Prepare data entry form
echo '<hr>';
echo
$crud->renderVertically();//READ and SHOW data

if($_POST['edit']){
    echo
'<hr>';
    echo
$crud->renderEditor($_POST['id']);//Prepare data edit form
}
?>