How to modify xml data using php - Part 1


In modify.php add the following code:
<?php
$modifybook = $_GET['bid'];
$doc = new DOMDocument();
$doc->load( 'loaned.xml' );
 
$booklist = $doc->getElementsByTagName( "book" );

foreach( $booklist as $book )
{
$bookids = $book->getElementsByTagName( "ID" );
$bookid = $bookids->item(0)->nodeValue;
if($bookid == $modifybook){
      $booktitles= $book->getElementsByTagName( "title" );
      $booktitle = $booktitles->item(0)->nodeValue;

      $dates= $book->getElementsByTagName( "date" );
      $date= $dates->item(0)->nodeValue;
     
      $retdates = $book->getElementsByTagName( "retdate" );
      $retdate = $retdates->item(0)->nodeValue;
     
      $sids = $book->getElementsByTagName( "SID" );
      $sid = $sids->item(0)->nodeValue;
      echo "<tr> 
     <td colspan=\"2\" class=\"labelcell\"><label for=\"btitle\">Book Title:</label></td>
     <td colspan=\"2\"class=\"fieldcell\"><input type=\"text\" value=\"$booktitle\" id=\"btitle\" name=\"btitle\"  tabindex=\"1\"/></td>
   </tr>
      <tr> 
     <td colspan=\"2\" class=\"labelcell\"><label for=\"bdate\">Book Issue date:</label></td>
     <td colspan=\"2\" class=\"fieldcell\"> <input type=\"text\" id=\"bdate\" name=\"bdate\" value=\"$date\"  tabindex=\"2\"/><br />
</td>
   </tr>
         <tr> 
     <td colspan=\"2\" class=\"labelcell\"><label for=\"bookrentdate\">Book Rent date:</label></td>
     <td colspan=\"2\" class=\"fieldcell\"> <input type=\"text\" id=\"bookrentdate\" value=\"$retdate\" name=\"bookrentdate\" tabindex=\"3\"/> <br />
</td>
   </tr>
   <tr>
 <td colspan=\"2\" class=\"labelcell\"><label for=\"booksid\">Book SID :</label></td>
    <td colspan=\"2\"><input type=\"text\" id=\"booksid\" name=\"booksid\" value=\"$sid\" tabindex=\"4\">
    <input type=\"hidden\" value=\"$bookid\" id=\"bid\" name=\"bid\" />
    </td></tr>
     </td>
   </tr>";   
  }
}
?>  
   <tr><td colspan="4"><input type="submit" name="upload" class="box" value="Update" tabindex="5" /></td></tr>
  </table> 
</form>

Then on submit of above form, it will call the update.php where we should use following code:
Click here  to read for How to modify xml data using php - Part 2

Comments

Popular posts from this blog

Leap Year Calculator

PDF form validation using javascript

Localhost firefox asking for password and username