Great
So Simple and clean. Thanks
<?php $conn = new mysqli('localhost', 'root', '', 'db_xml'); if(!$conn){ } ?>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP - Generate XML File</h3> <hr style="border-top:1px dotted #ccc;"/> <button type="button" class="btn btn-success" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add member</button> <a href="export.php" class="btn btn-primary pull-right"><span class="glyphicon glyphicon-export"></span> Export as XML</a> <br /><br /> <table class="table table-bordered"> <thead class="alert-info"> <tr> <th>Firstname</th> <th>Lastname</th> <th>Address</th> </tr> </thead> <tbody style="background-color:#fff;"> <?php require 'conn.php'; while($fetch = $query->fetch_array()){ ?> <tr> <td><?php echo $fetch['firstname']?></td> <td><?php echo $fetch['lastname']?></td> <td><?php echo $fetch['address']?></td> </tr> <?php } ?> <tbody> </table> </div> <div class="modal fade" id="form_modal" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-dialog" role="document"> <form action="save_member.php" method="POST" enctype="multipart/form-data"> <div class="modal-content"> <div class="modal-body"> <div class="col-md-2"></div> <div class="col-md-8"> <div class="form-group"> <label>Firstname</label> <input type="text" name="firstname" class="form-control" required="required"/> </div> <div class="form-group"> <label>Lastname</label> <input type="text" name="lastname" class="form-control" required="required"/> </div> <div class="form-group"> <label>Address</label> <input type="text" name="address" class="form-control" required="required"/> </div> </div> </div> <div style="clear:both;"></div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button> <button name="save" class="btn btn-primary"><span class="glyphicon glyphicon-save"></span> Save</button> </div> </div> </form> </div> </div> </body> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/bootstrap.js"></script> </html>
<?php require_once 'conn.php'; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $address = $_POST['address']; $conn->query("INSERT INTO `member` VALUES('', '$firstname', '$lastname', '$address')") or die($conn->error()); } ?>
<?php require 'conn.php'; $xml = new DomDocument("1.0", "UTF-8"); $person = $xml->createElement("person"); $person = $xml->appendChild($person); while($fetch = $query->fetch_array()){ $member = $xml->createElement("member"); $member = $person->appendChild($member); $firstname = $xml->createElement("firstname", $fetch['firstname']); $firstname = $member->appendChild($firstname); $lastname = $xml->createElement("lastname", $fetch['lastname']); $lastname = $member->appendChild($lastname); $address = $xml->createElement("address", $fetch['address']); $address = $member->appendChild($address); } $xml->FormatOutput = true; $string_value = $xml->saveXML(); $xml->save("member.xml"); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/> </head> <body> <nav class="navbar navbar-default"> <div class="container-fluid"> <a class="navbar-brand" href="https://sourcecodester.com">Sourcecodester</a> </div> </nav> <div class="col-md-3"></div> <div class="col-md-6 well"> <h3 class="text-primary">PHP - Generate XML File</h3> <hr style="border-top:1px dotted #ccc;"/> <center><h4>XML File has Been Generated</h4></center> <center><a href="member.xml">Click here to open the file</a></center> <a href="index.php">Back</a> </body> </html>