- Create a employee.html file to get data form user.
- Create a edit.php file to save data in XML.
Here we are creating employee.html file here we will write a code to create a form.
<form method="POST" action="edit.php">
<div class="row form-group">
<div class="col-sm-2">
<label class="control-label">Employee Name:</label>
</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="employee" value="John">
</div>
</div>
<div class="row form-group">
<div class="col-sm-2">
<label class="control-label">Team Name:</label>
</div>
<div class="col-sm-10">
<select class='form-control' name='teamname'>
<option selected>Dev</option>
<option>Seo</option>
</select>
</div>
</div>
<div class="form-footer">
<button type="submit" name="edit" class="btn btn-primary">Save</button>
</div>
</form>
Create edit.php file to update data in XML
<?php
session_start();
if(isset($_POST['edit'])){
$employee = simplexml_load_file('employee.xml');
foreach($employee->emp as $emp){
if($emp->id == $_POST['id']){
$emp->teamname = $_POST['teamname'];
$emp->employee = $_POST['employee'];
break;
}
}
file_put_contents('employee.xml', $employee->asXML());
$_SESSION['message'] = 'Employee updated successfully';
header('location: '.$_SERVER['HTTP_REFERER']);
}
else{
header('location: '.$_SERVER['HTTP_REFERER']);
}
?>
Thanks
I am sure this piece of writing has touched all the internet viewers, its really really
good post on building up new web site.