2

PHP Simple XML Parser, blank response.

The main problem with the code below is that without the parser it will work fine but as soon as the XML parser is added, so it can connect to the other server from the client, it will not return with the results, just a blank page?

Also this is a project, so before anyone ask's, why do you not have any SQLi protection. I have not as of yet implemented it yet.

Here is the code below:

Client side XML parser code: hinphp.php

<?php
  $hin = $_GET["hin"];
  $connection = curl_init();
  curl_setopt($connection, CURLOPT_URL, "http://192.168.0.12/hinbuy.php?hin="); 
  curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($connection,CURLOPT_HEADER, 0);
  $response = curl_exec($connection);
  $xml = simplexml_load_string($response);
  for($index=0; $index < count($xml->songs); $index++)
  {
        echo $xml->songs[$index]->ID . "<br />";
        echo $xml->songs[$index]->song . "<br />";
        echo $xml->songs[$index]->artist . "<br />";
        echo $xml->songs[$index]->year . "<br />";
        echo $xml->songs[$index]->genre . "<br />";
        echo $xml->songs[$index]->quantity . "<br />";

        $ID = $xml->songs[$index]->ID;
        echo "<a href='http://192.168.0.12/buyclihin.php?ID=$ID'>buy</a>";
  }

  curl_close($connection);
  ?>

Server side PHP select code: hinbuy.php

<?php
  header("Content-type: text/xml");
  echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
  echo "<hit>";
  $hin = $_GET["hin"];
  $conn = new PDO("mysql:host=localhost;dbname=xxxxx;","xxxxx","xxxxx");
  $results = $conn->query("SELECT * FROM `ghit` WHERE `artist`='$hin'");
  while($row=$results->fetch())
  {
  echo "<songs>";
  echo "<id>$row[ID]</id>";
  echo "<song>$row[song]</song>";
  echo "<artist>$row[artist]</artist>";
  echo "<year>$row[year]</year>";
  echo "<genre>$row[genre]</genre>";
  echo "<quantity>$row[quantity]</quantity>";
  echo "</songs>";
  }
  echo "</hit>"
  ?>

1 Answer 1

1

Is it probably because you are not passing $hin to hibbuy.php?

Try:

$hin = $_GET["hin"];
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, "http://192.168.0.12/hinbuy.php?hin=" . $hin);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.