THE WORLD'S LARGEST NEWS, ENTERTAINMENT AND TECHNOLOGY SITE
We are on
×

MEMBERS LOGIN








TESTIMONIES
TESTIMONIES :
Sixtjohn
August 1, 2018

Wow' I got paid for my post'

I'm happily thanking Naijacrawl.com for paying for my post and crediting my account.

 


davidenabs
June 12, 2018

Enjoying all the benefits of this great site and do not share my own testiomoies, to be frank, it won't be fair.

NiajaCrawl is really blessed, I thank all the team members and most especially the CEO, the concept about the site is too muchtwothumb

One area I really love so much about the site, is the community forum , it has really helped me alot, asking questions and getting helpful answers. (NaijaCrawl has expanded my knowledge on BOOTSTRAP most especially and others).

Kudos to NaijaCrawl

Fans please invite friends and loved once to also enjoy the benefit of NaijaCrawl


Infopee
March 25, 2018

I just want to say a big thank you to NAIJACRAWL for keeping their promise just got paid 3k in my account for a competition I participated in, Naijacrawl is the best, you guys are awesome . ...... .    

 


laravel
February 21, 2018
Thanks to naijacrawl for fulfilling their promise , I received the 3Gb plus 3k in my account. Am very happy

melodyogonna
February 12, 2018

Best website i have seen, i just love this website, keep it up bro.


Sixtjohn
December 7, 2017

Naijacrawl is incredible, I never believed until I was convinced, I was paid for my posts and I withdrew 20$ from my Naijacrawl account, I got paid in my local account in less than 24hr,

Naijacrawl is for real, a trial just convinced me.

Thanks to Naijacrawl and Team for crediting my account. 


laravel
November 29, 2017

hi guys, i love these site, it has awesome features which am enjoying right now, join me and give your own testimony.


emmanuelibu
November 12, 2017

Hi there, my name is Emmanuel Ibu, I registered here on Naijacrawl about 3 Months ago and began work, by work I mean I write articles and essays on the latest local and international stories, music, sports, health, politics e.t.c. in my spare time. I must say it has been a rewarding experience, I was a bit sceptical that I won’t get paid whenever I got to my 15$ threshold but lo and behold I did get paid in less than 24hrs after I clicked on the withdraw button and entered my bank details. Naijacrawl is for real, do register, get creative and earn, I assure you, you won’t regret it. Ciao!!!  




ADVERT SPACE

get anything you want people to know about

You can place your advert here.

BUY NOW


ADVERT SPACE

get anything you want people to know about

You can place your advert here.

BUY NOW

Join Us On Facebook

phpmysql Webmaster
    Learn PHP OOP (insert,delete,update,dbconnection)

Posted by kizinho May 22, 2018

    Learn php OOP  method.  Today will show you guys how to learn OOP ( object orientated programming ) 

    This file  I will work on contains the following 

    Oop

     

    ADD-Data.php

    <?php include_once 'dbconfig.php'; 
    if(isset($_POST['btn-save'])) 
    { $fname = $_POST['first_name'];
     $lname = $_POST['last_name']; 
     $email = $_POST['email_id'];
     $contact = $_POST['contact_no'];
     if($crud->create($fname,$lname,$email,$contact)) 
     { header("Location: add-data.php?inserted"); } 
     else { header("Location: add-data.php?failure"); } } ?>
     <?php include_once 'header.php'; ?> 
     <div class="clearfix"></div>
     <?php if(isset($_GET['inserted'])) 
     { ?> <div class="container"> <div class="alert alert-info"> 
     <strong>WOW!</strong> Record was inserted successfully <a href="index.php">HOME</a>! 
     </div> </div> <?php } else if(isset($_GET['failure'])) { ?> <div class="container"> <div class="alert alert-warning"> 
     <strong>SORRY!</strong> ERROR while inserting record ! </div> </div> <?php } ?> <div class="clearfix"></div><br /> 
     <div class="container"> <form method='post'> <table class='table table-bordered'> <tr> <td>First Name</td> <td>
     <input type='text' name='first_name' class='form-control' required></td> </tr> <tr> <td>Last Name</td> <td>
     <input type='text' name='last_name' class='form-control' required></td> </tr> <tr> <td>Your E-mail ID</td> <td><input type='text' name='email_id' class='form-control' required></td> </tr> <tr> <td>Contact No</td> <td><input type='text' name='contact_no' class='form-control' required></td> </tr> <tr> <td colspan="2"> <button type="submit" class="btn btn-primary" name="btn-save"> <span class="glyphicon glyphicon-plus"></span> Create New Record </button> <a href="index.php" class="btn btn-large btn-success"><i class="glyphicon glyphicon-backward"></i> &nbsp; Back to index</a> </td> </tr> </table> </form> </div> 
    

    Add data is for inserting your data's , you will get the download link at the end.

    Class.Crud.php

    is a function using oop  to insert , update and delete, it is inform of the controller 

    
    
    <?php class crud {
    
     private $db; 
     
     function __construct($DB_con)
    
     { $this->db = $DB_con; }
    
     public function create($fname,$lname,$email,$contact) 
     
     { try { $stmt = $this->db->prepare("INSERT INTO tbl_users(first_name,last_name,email_id,contact_no) VALUES(:fname, :lname, :email, :contact)"); 
     $stmt->bindparam(":fname",$fname);
     $stmt->bindparam(":lname",$lname);
     $stmt->bindparam(":email",$email);
     $stmt->bindparam(":contact",$contact); 
     $stmt->execute(); return true; 
     } 
     catch(PDOException $e) 
     { 
     echo $e->getMessage(); return false; 
     } 
     } 
     public function getID($id) 
     { 
     $stmt = $this->db->prepare("SELECT * FROM tbl_users WHERE id=:id");
     $stmt->execute(array(":id"=>$id));
     $editRow=$stmt->fetch(PDO::FETCH_ASSOC); return $editRow; 
     }
     public function update($id,$fname,$lname,$email,$contact) 
     { 
     try {
     $stmt=$this->db->prepare("UPDATE tbl_users SET first_name=:fname, last_name=:lname, email_id=:email, contact_no=:contact WHERE id=:id ");
     $stmt->bindparam(":fname",$fname);
     $stmt->bindparam(":lname",$lname);
     $stmt->bindparam(":email",$email); 
     $stmt->bindparam(":contact",$contact); 
     $stmt->bindparam(":id",$id); 
     $stmt->execute(); return true; 
     } 
     catch(PDOException $e) 
     { 
     echo $e->getMessage(); return false; 
     } 
     } public function delete($id) 
     { $stmt = $this->db->prepare("DELETE FROM tbl_users WHERE id=:id"); 
     $stmt->bindparam(":id",$id); $stmt->execute(); return true; 
     } 
     /* paging */
     public function dataview($query) 
     { 
     $stmt = $this->db->prepare($query); $stmt->execute();
     if($stmt->rowCount()>0)
     { 
     while($row=$stmt->fetch(PDO::FETCH_ASSOC))
     { 
     ?> <tr> <td><?php print($row['id']); ?></td> 
     <td><?php print($row['first_name']); ?></td>
     <td><?php print($row['last_name']); ?></td> 
     <td><?php print($row['email_id']); ?></td> 
     <td><?php print($row['contact_no']); ?></td> 
     <td align="center"> <a href="edit-data.php?edit_id=<?php print($row['id']); ?>">
     <i class="glyphicon glyphicon-edit"></i></a> </td> <td align="center"> 
     <a href="delete.php?delete_id=<?php print($row['id']); ?>">
     <i class="glyphicon glyphicon-remove-circle"></i></a> </td> 
     </tr> <?php } } else { ?> <tr> <td>Nothing here...</td> </tr> 
     <?php } } public function paging($query,$records_per_page) 
     { $starting_position=0; if(isset($_GET["page_no"])) 
     { $starting_position=($_GET["page_no"]-1)*$records_per_page; } 
     $query2=$query." limit $starting_position,$records_per_page"; return $query2;
     }
     public function paginglink($query,$records_per_page)
     { $self = $_SERVER['PHP_SELF']; $stmt = $this->db->prepare($query); $stmt->execute(); 
     $total_no_of_records = $stmt->rowCount(); 
     if($total_no_of_records > 0)
     { ?>
     <ul class="pagination">
     <?php $total_no_of_pages=ceil($total_no_of_records/$records_per_page); $current_page=1; 
     if(isset($_GET["page_no"])) { $current_page=$_GET["page_no"]; } if($current_page!=1) 
     { $previous =$current_page-1; echo "<li><a href='".$self."?page_no=1'>First</a></li>"; 
     echo "<li><a href='".$self."?page_no=".$previous."'>Previous</a></li>"; } 
     for($i=1;$i<=$total_no_of_pages;$i++) 
     { if($i==$current_page) { echo "<li><a href='".$self."?page_no=".$i."' style='color:red;'>".$i."</a></li>"; } 
     else { echo "<li><a href='".$self."?page_no=".$i."'>".$i."</a></li>"; } } 
     if($current_page!=$total_no_of_pages) { $next=$current_page+1; 
     echo "<li><a href='".$self."?page_no=".$next."'>Next</a></li>";
     echo "<li><a href='".$self."?page_no=".$total_no_of_pages."'>Last</a></li>"; } ?></ul><?php } } 
     /* paging */ }

    Dbconfig.php

    <?php $DB_host = "localhost"; 
    $DB_user = "root"; 
    $DB_pass = ""; 
    $DB_name = "oop"; 
    try { $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
     $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); }
     catch(PDOException $e) { echo $e->getMessage(); 
     } include_once 'class.crud.php'; $crud = new crud($DB_con); 
     ?>

    Edit-Data.php

    <?php include_once 
    'dbconfig.php'; 
    if(isset($_POST['btn-update'])) { $id = $_GET['edit_id']; 
    $fname = $_POST['first_name']; 
    $lname = $_POST['last_name']; $email = $_POST['email_id']; $contact = $_POST['contact_no']; 
    
    
    if($crud->update($id,$fname,$lname,$email,$contact))
     { $msg = "<div class='alert alert-info'> 
    
    <strong>WOW!</strong> Record was updated successfully <a href='index.php'>HOME</a>!
     </div>"; } else { $msg = "<div class='alert alert-warning'> 
    
    <strong>SORRY!</strong> ERROR while updating record ! </div>"; } } 
    if(isset($_GET['edit_id'])) { $id = $_GET['edit_id']; extract($crud->getID($id)); } ?>
     <?php include_once 'header.php'; ?> 
    <div class="clearfix"></div>
     <div class="container">
     <?php if(isset($msg))
     { echo $msg; } ?> </div> <div class="clearfix"></div><br /> 
    <div class="container"> <form method='post'> 
    <table class='table table-bordered'> 
    <tr> 
    <td>First Name</td> 
    <td><input type='text' name='first_name' class='form-control' value="<?php echo $first_name; ?>" required>
    </td> 
    </tr>
     <tr> 
    <td>Last Name</td> 
    <td><input type='text' name='last_name' class='form-control' value="<?php echo $last_name; ?>" required></td> 
    </tr>
     <tr> 
    <td>Your E-mail ID</td> <td><input type='text' name='email_id' class='form-control' value="<?php echo $email_id; ?>" required>
    </td> </tr> <tr> <td>Contact No</td> <td><input type='text' name='contact_no' class='form-control' value="<?php echo $contact_no; ?>" required>
    </td> 
    </tr> <tr> 
    <td colspan="2"> <button type="submit" class="btn btn-primary" name="btn-update"> <span class="glyphicon glyphicon-edit"></span> Update this Record </button> 
    <a href="index.php" class="btn btn-large btn-success"><i class="glyphicon glyphicon-backward"></i> 
    &nbsp; CANCEL</a> </td> </tr>
     </table> 
    </form> </div>

    Delete.php

    <?php include_once 'dbconfig.php'; if(isset($_POST['btn-del'])) 
    { $id = $_GET['delete_id']; $crud->delete($id); header("Location: delete.php?deleted"); } ?>
     <?php include_once 'header.php'; ?> <div class="clearfix"></div> 
    <div class="container"> <?php if(isset($_GET['deleted']))
     { ?> <div class="alert alert-success"> <strong>Success!</strong> record was deleted... </div>
     <?php } else { ?> <div class="alert alert-danger"> <strong>Sure !</strong> to remove the following record ? </div> <?php } ?> </div> <div class="clearfix"></div> 
    <div class="container"> <?php if(isset($_GET['delete_id'])) { ?> <table class='table table-bordered'>
     <tr> <th>#</th>
     <th>First Name</th>
     <th>Last Name</th>
     <th>E - mail ID</th> <th>Gender</th>
     </tr> 
    <?php $stmt = $DB_con->prepare("SELECT * FROM tbl_users WHERE id=:id"); 
    $stmt
    >execute(array(":id"=>$_GET['delete_id'])); while($row=$stmt->fetch(PDO::FETCH_BOTH)) { ?>
     <tr> <td>
    <?php print($row['id']); ?></td> <td>
    <?php print($row['first_name']); ?></td>
     <td>
    <?php print($row['last_name']); ?></td> <td>
    <?php print($row['email_id']); ?></td>
     <td>
    <?php print($row['contact_no']); ?></td>
     </tr> <?php } ?> </table> <?php } ?> </div>
     <div class="container"> <p>
     <?php if(isset($_GET['delete_id'])) { ?> <form method="post"> <input type="hidden" name="id" value="<?php echo $row['id']; ?>" /> 
    
    <button class="btn btn-large btn-primary" type="submit" name="btn-del">
    <i class="glyphicon glyphicon-trash"></i> &nbsp; YES</button> <a href="index.php" class="btn btn-large btn-success">
    <i class="glyphicon glyphicon-backward"></i> &nbsp; NO</a> </form> <?php }
     else { ?> <a href="index.php" class="btn btn-large btn-success"><i class="glyphicon glyphicon-backward"></i> &nbsp; Back to index</a> <?php } ?> 
    </p> </div> 

    Index.php is the access page 

    <?php include_once 'dbconfig.php'; ?>
     <?php include_once 'header.php'; ?> 
     <div class="clearfix"></div> <div class="container"> 
     <a href="add-data.php" class="btn btn-large btn-info">
     <i class="glyphicon glyphicon-plus"></i> &nbsp; Add Records</a> </div>
     
     <div class="clearfix"></div><br /> <div class="container"> 
     <table class='table table-bordered table-responsive'> 
     <tr> 
     <th>#</th>
     <th>First Name</th>
     <th>Last Name</th> 
     <th>E - mail ID</th> 
     <th>Contact No</th> 
     <th colspan="2" align="center">Actions</th> 
     </tr> 
     <?php $query = "SELECT * FROM tbl_users"; $records_per_page=3; $newquery = $crud->paging($query,$records_per_page); $crud->dataview($newquery); ?>
     <tr> 
     <td colspan="7" align="center">
     <div class="pagination">
     <?php $crud->paginglink($query,$records_per_page); ?> </div> </td> 
     </tr> </table>
     </div> 
    

    Table.php 

    Is to create your table if not exist 

    Download Code

    If any problem drop in our comment box. Thanks

    TRY IT YOURSELF



      Code                               Output
                        
            

     Fresh and Hot Updates!!

    Also Read :

    Click Here To Comment



    FOLLOW US ON:-


    RELATED POSTS
    Learn PHP OOP (insert,delete,update,dbconnection)
    Kizinho | 6 months ago
    Comment

    How to use Concatenation in Php .
    Kizinho | 8 months ago
    Comment

    MOST VIEWED
    How to use Concatenation in Php .
    Kizinho | 8 months ago
    Comment

    Learn PHP OOP (insert,delete,update,dbconnection)
    Kizinho | 6 months ago
    Comment


    =Comment Wisely no offensive words===

    0 Comment
    No Comment Yet












    Prove that you are Human





DONATE FOR US


CONTACT US FOR ADVERT

GET NAIJACRAWL SCRIPT OR HIRE A WEB DEVELOPER
Subscribe to our weekly newsletter



logo Face of Naijacrawl


HOT VIDEO !!!

Video: XXXTentacion Moonlight ( Mp4 )

Chat Us on
×

Artist of the Week
DEEJAY J MASTA ANI FT PHYNO & FLAVOUR MP3

EEJAY-J-MASTA-ANI-FT-PHYNO-FLAVOUR-MP3-.jpg

Video of the Week

NC TRENDING POSTS