How to modify xml data using php - Part 2

Use the following code to update the submitted value from modify.php into xml:
<?php
function update_book_id($id, $filename = 'loaned.xml')
{
$data = simplexml_load_file($filename);
for($i = 0, $length = count($data->resource->book); $i < $length; $i++)
    {
    if($data->resource->book[$i]->ID == $id)
        {
       
        $btitle = $_POST['btitle'];        
        $bdate = $_POST['bdate'];
        $bookrentdate = $_POST['bookrentdate'];
        $booksid = $_POST['booksid'];
       
        $data->resource->book[$i]->title = $btitle;
        $data->resource->book[$i]->date = $bdate;
        $data->resource->book[$i]->retdate = $bookrentdate;
        $data->resource->book[$i]->SID = $booksid;
        break;
        }
    }
    file_put_contents($filename, $data->saveXML());
    //echo $deletingbook." Deleted !!!";
}
//SAMPLE USAGE
$updatingbook = $_POST['bid'];
echo $updatingbook;
update_book_id ($updatingbook);
header("Location:index.php");  
//delete_book_id('Book 1');
?>

Comments

Popular posts from this blog

Python commands for Mac and Windows

Drive are not opening in same window on double click in windows XP

Unable to Start Debugging on the Web Server