Thursday, November 22, 2018

How to delete data from database using MVC?


Delete data from database using MVC

You can easily delete the records from database. In this below example we have used three php files

1. View.php

<?php
include("controller.php");
//delete the data
 if(isset($_REQUEST['del_id']))
 {
   $del=$_REQUEST['del_id'];

   $obj->delete($del);
   header("location:view.php");
}
?>
<html >
<head>
<title>Delete the data</title>
</head>
<body>
<form method="post" >
 <table align="center" border="1">
  <tr>
   <th>Uid</th>
   <th>Uname</th>
   <th>Password</th>
   <th colspan="2">Action</th>
  </tr>
  <?php
  while($r = mysql_fetch_array($s))
  {
  ?>
  <tr>
   <td><?php echo $r['uid']; ?></td>
   <td><?php echo $r['uname']; ?></td>
   <td><?php echo $r['pass']; ?></td>
   <td><a href="view.php?del_id=<?php echo $r['uid']; ?>">delete</td>
  </tr>
  <?php
  }
  ?>
 </table>
</form>
</body>
</html>
 

2. Model.php


<?php

public function delete($del){
  $del="delete from user where uid='$del'";
  $ex=mysql_query($del);
 }
?>



3. Controller.php



<?php
 include("model.php");
  public function delete($del){
  $obj=new model();
  $obj->delete($del);
 }
?>

Related Posts:

  • How can insert the data in mysql using php? step 1:- Firstly create a database name & secondly create a table in MySQL. step 2:-After that create a table structure eg. Column Name1 , Coulmn Name2 , Coulmn NameN... <?php mysql_connect("localhost","root"… Read More
  • How can fetch the records in MySQL using php? Create  a  form.php  for the inserting data & view.php for the fetching data in the  Data base Fetching Records  in the database using Mysql_fetch_array ( ) Function. Select Command use for the … Read More
  • MySql Quaries You can create and populate the example table with these statements: CREATE TABLE shop ( article INT(4) UNSIGNED ZEROFILL DEFAULT '0000' NOT NULL, dealer CHAR(20) DEFAULT '' NOT NULL, p… Read More
  • PHP Error Types - And their Differences Notices : It will be shown in below condition like if we will try to access a variable which is not defined yet. it will not stop script execution. Warning : It will be shown while using include(), it will not a… Read More
  • OOP PHP Login Tutorial   What is a PHP Secure Login System with Registration? Many applications need to register and authenticate users. Some users have developed their own packages for this purpose, others have used existing p… Read More

0 comments:

Post a Comment