MySQL-PHP-XML output -
i'm relatively inexperienced programmer trying work through current project. basically, i'm designing feature database; using search query able have information inserted form letter. @ point, i'm trying translate results search xml format using xmlwriter, unfortunately search page isn't being generated anymore. i'm using code based on solution offered i've included php code below, , feedback welcome
<?php session_start(); include 'conn.php'; if(empty($_session['username']) || empty($_session['password'])) print("access database denied"); else { $username = $_session['username']; $password = $_session['password']; $type = $_session['type']; if($type == "admin") { include '../includes/aheader.html'; } if($type == "user") { include '../includes/uheader.html'; } if(isset($_post["searchbutton"])) { $keyword = $_post['keyword']; $choice = $_post['choice']; if($choice == "company_name") $sql = $mysqli -> prepare("select * clients company_name ?"); if($choice == "project_code") $sql = $mysqli -> prepare("select * clients project_code ?"); $keyword = '%'.$keyword.'%'; $sql -> bind_param('s', $keyword); $sql -> execute(); $result = $sql -> get_result(); if(!$result) print("<p>select query failed</p>"); else { if($result -> num_rows == 0) print("<p>no match found</p>"); else { header("content-type: text/html/force-download"); header("content-disposition: attachment; filename='file_name.xml'"); $xml = new xmlwriter(); $xml -> openuri("test.xml"); $xml -> startdocument("1.0", "utf-8"); $xml -> setindent(true); while($row = mysql_fetch_assoc($results)) { $xml -> startelement("clients"); $xml -> writeattribute('company_name', $row['company_name']); $xml -> writeattribute('phone', $row['phone']); $xml -> writeattribute('address', $row['address']); $xml -> writeattribute('approximate_employees', $row['approximate_employees']); $xml -> writeattribute('project_code', $row['project_code']); $xml -> writeraw($row['clients']); $xml -> endelement(); } $xml -> endelement(); header('content-type: text/xml'); $xml -> flush(); } } } } ?>
Comments
Post a Comment