Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to send and receive a xml to another computer
    primarykey
    data
    text
    <p>I have two computers, comp 1 as branch 1 and comp 2 as main branch. in comp 1 i have generated an xml of my database query using php. </p> <pre><code>`&lt;?php header ("Content-Type:text/xml"); //database configuration $config['mysql_host'] = "localhost"; $config['mysql_user'] = "root"; $config['mysql_pass'] = "donnaluz"; $config['db_name'] = "global89_branch1"; $config['table_name'] = "branchsales"; //connect to host mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']); //select database @mysql_select_db($config['db_name']) or die( "Unable to select database"); $xml = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;"; $root_element = $config['table_name']; $xml = "&lt;$root_element&gt;"; /*$title = $doc-&gt;createElement("branchsales"); $title = $root-&gt;appendChild($title); $text = $doc-&gt;createTextNode("sales"); $text = $title-&gt;appendChild($text); */ //select all items in table $sql = "SELECT branch.branchname,branchadmin.username,branchcomp.*,branchsales.*,days.day FROM branchsales,branch,branchadmin,branchcomp,days WHERE branchsales.comp_id = branchcomp.comp_id AND branchsales.admin_id = branchadmin.admin_id AND branchsales.branch_id = branch.branch_id AND branchsales.day_id = days.day_id"; $result = mysql_query($sql); if (!$result) { die('Invalid query: ' . mysql_error()); } if(mysql_num_rows($result)&gt;0) { while($result_array = mysql_fetch_assoc($result)) { $xml .= "&lt;".$config['table_name']."&gt;"; //loop through each key,value pair in row foreach($result_array as $key =&gt; $value) { //$key holds the table column name $xml .= "&lt;$key&gt;"; //embed the SQL data in a CDATA element to avoid XML entity issues $xml .= "&lt;![CDATA[$value]]&gt;"; //and close the element $xml .= "&lt;/$key&gt;"; } $xml.="&lt;/".$config['table_name']."&gt;"; } //close the root element $xml .= "&lt;/$root_element&gt;"; //send the xml header to the browser header ("Content-Type:text/xml"); echo $xml; ?&gt; </code></pre> <p>` which looks like this </p> <pre><code>&lt;branchsales&gt; &lt;branchname&gt;Branch1&lt;/branchname&gt; &lt;username&gt;garfield&lt;/username&gt; &lt;comp_id&gt;1&lt;/comp_id&gt; &lt;admin_id&gt;1&lt;/admin_id&gt; &lt;pcnum&gt;1&lt;/pcnum&gt; &lt;starttime&gt;09:00:00&lt;/starttime&gt; &lt;endtime&gt;10:00:00&lt;/endtime&gt; &lt;totaltime&gt;1:00:00&lt;/totaltime&gt; &lt;compcharge&gt;10.00&lt;/compcharge&gt; &lt;id&gt;1&lt;/id&gt; &lt;branch_id&gt;1&lt;/branch_id&gt; &lt;day_id&gt;5&lt;/day_id&gt; &lt;timeopened&gt;8:00:00&lt;/timeopened&gt; &lt;timeclosed&gt;23:00:00&lt;timeclosed&gt; </code></pre> <p>blah blah.. so on..</p> <p>The thing is, I want that generated xml to be sent out to comp 2, looking like this in a table</p> <hr> <h2>|ID|Day |Watcher |Branch | Current Date | Time Opened | Time closed | PC No. | so on...</h2> <p>1 Friday garfield Branch1 29-03-13 8:00:00 23:00:00 1</p> <p>THIS IS MY SEND CODE, BUT ITS NOT WORKING</p> <pre><code>&lt;? php $file = 'http://localhost/thesis/xmldailyrep.php'; $xml_builder = 'simplexml_load_file($file)'; $ch = curl_init("http://172.16.0.55/dailyrep1.php"); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:text/xml')); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_REFERER, "http://localhost/thesis/xmldailyrep.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $ch_result = curl_exec($ch); curl_close($ch); echo $ch_result; ?&gt; </code></pre> <p>MY RECEIVE CODE IN COMP 2 is this</p> <pre><code>&lt;?php /* * XML Server. */ // We use php://input to get the raw $_POST results. $xml_post = file_get_contents('xmldailyrep.php'); // If we receive data, save it. if ($xml_post) { $xml_file = 'received_xml_' . date('Y_m_d-H-i-s') . '.xml'; $fh = fopen($xml_file, 'w') or die(); fwrite($fh, $xml_post); fclose($fh); // Return, as we don't want to cause a loop by processing the code below. return; } ?&gt; </code></pre> <p>PLEASE HELP</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload