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

CSS Mouse Cursors and Custom Cursors

Block right click or disable keyboard on web pages

What is PAD file? "Submit your software with PAD file to Download.com"