- Make a request to delete data from xml.
- Create a delete.php file.
Make an request to delete data from xml.
request vatiable name = “id”
example: id=”1″;
Create a delete.php file and add below code.
<?php
$id = $_GET['id'];
$employee = simplexml_load_file('employee.xml');
//we're are going to create iterator to assign to each user
$index = 0;
$i = 0;
foreach($employee->emp as $emp){
if($emp->id == $id){
$index = $i;
break;
}
$i++;
}
unset($employee->emp[$index]);
file_put_contents('employee.xml', $employee->asXML());
$_SESSION['message'] = 'Employee deleted successfully';
header('location: '.$_SERVER['HTTP_REFERER']);
?>
Thanks