PHP oops insert.php

how do we insert data in PHP via OOPS Concepts

<?php
 require_once("../inc/config.php");// .. used for this folder is in root directory
 include_once("all_function.php");  // here insert functions running 
 class InsertData {
private $id; 
private $db;

 function __construct() 
{    
 $this->db = new Database();  
 $this->fun = new AllFunction(); 

}

public function insertTestUs(){

if(isset($_POST['atitle'])){
             $atitle = $_POST['atitle'];
         }else{
             $atitle = "";
         }
if(isset($_POST['aheading'])){
             $aheading = $_POST['aheading'];
     }else{         $aheading = "";     
}

if(isset($_POST['id'])){
             $about_id = $_POST['id'];
         }

if(isset($about_id) && $about_id > 0){
             if($atitle != "" && $aheading != ""){
                 //update query
                 $query = "UPDATE querypanel_about_us SET atitle='$atitle', aheading='$aheading' WHERE about_id ='$about_id'";
                 $this->db->execute($query);
                     echo 0;
             }else{
                 echo 1;
             }

}else{
             if($atitle != "" && $aheading != ""){ 
                 // insert query
                 $query = "INSERT INTO querypanel_about_us(atitle, aheading) VALUES('$atitle','$aheading')";
                 $this->db->execute($query);
                     echo 0;
         }else{             echo 1;         
    }     
   } 
  }
 }
?>


Here i also mention the all function what i have used to included 


<?php 
 class AllFunction
 {

private $data; 
public function escape($data)
{     
$this->data = $data;   
//  mysqli_real_escape_string() function escapes special characters in a string   
//rtrim - remove character from right side of string
$value = mysqli_real_escape_string(rtrim($data));     return $value; 
 }
}
?>

7 thoughts on “PHP oops insert.php

Leave a Reply

Your email address will not be published. Required fields are marked *