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);
}
?>
0 comments:
Post a Comment