I'm trying to parse an xml feed into mysql database using php. I get this error when i execute the script...not sure why? Error 320 (net::ERR_INVALID_RESPONSE): Unknown error.

I'm trying to parse an xml feed into mysql database using php. I get this error when i execute the script...not sure why? Error 320 (net::ERR_INVALID_RESPONSE): Unknown error.

I downloaded the file as uncompressed xml and uploaded it to my server...I just can;t get it to write into the database!?!?
<?php 
require_once ('connect.php'); 
db_connect();
 
$xmlReader = new XMLReader();
 
$filename = "Get_Me_In.xml";
$url = "https://feeds.perfb.com/index.php/download?OEMAIL=danielrafique@vyceversa.co.uk&PX=d0310005b5e00cc254c6bc3c1fe075f0&DISPLAYFORMAT=XML&REVERSEMAPXML=yes&PRODUCTDB_ID=357";
file_put_contents($filename, file_get_contents($url));
 
$xmlReader->open($filename); 
 
while ($xmlReader->read()) 
{
 
switch ($xmlReader->name)
{
case 'product':
 
$dom = new DOMDocument();
$domNode = $xmlReader->expand();
$element = $dom->appendChild($domNode);
$domString = utf8_encode($dom->saveXML($element));
$product = new SimpleXMLElement($domString);
 
$product_code = $product->product_code;
$product_name = $product->product_name;
$level1 = $product->level1;
$level2 = $product->level2;
$description = $product->description;
$buyat_short_deeplink_url = $product->buyat_short_deeplink_url;
 
$image_url = $product->image_url;
$currency = $product->currency;
$price = $product->online_price;
$city = $product->city;
$country = $product->country;
$event_date = $product->event_date;
$event_venue = $product->event_venue;
$number_available = $product->number_available;
 
if (strlen($product_code)> 0)
{
echo "REPLACE INTO icanget_tickets
(product_code, product_name, level1, level2, description, buyat_short_deeplink_url, image_url, currency, price, country, event_date, event_venue, number_available)
 
VALUES ('$product_code', '$product_name', '$level1', '$level2', '$description', '$buyat_short_deeplink_url', '$image_url', '$currency', '$price', '$country', '$event_date', '$event_venue', '$number_available')";
if(!$query) die(mysql_error()); 
echo $product_name . "has been inserted </br>";
}
break;
 
}
 
}
 
?>

Open in new window

rafique12Asked:
Who is Participating?
 
Chris HarteConnect With a Mentor ThaumaturgeCommented:
You are trying to connect to a secure server, https, do you have openssl installed?

http://uk.php.net/manual/en/book.openssl.php
0
 
Chris HarteThaumaturgeCommented:
A 320 error is usually a connection to the server problem, which in this case could be your database server.
Bracket the variable in the values, see if that helps.
VALUES ('{$product_code}', '{$product_name}', '{$level1}', '{$level2}', '{$description}', '{$buyat_short_deeplink_url}', '{$image_url}', '{$currency}', '{$price}', '{$country}', '{$event_date}', '{$event_venue}', '{$number_available}')";

Open in new window

0
 
Roger BaklundCommented:
This is not a PHP error.

Are you using Chrome? Can you try with a different browser?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
rafique12Author Commented:
yeah i am using chrome. i get page cannot be displayed when i use IE also
0
 
Chris HarteThaumaturgeCommented:
I have just started to downloaded the file with chrome. I got to 100Mb and gave up.

THAT IS HUGE!

Check your download limits in anywhere that might be setting a connection limit such as firewall software.
0
 
Roger BaklundCommented:
I have low bandwidth, so I can not wait for the entire page to load, but it does start to load when I use Firefox 3.0.9, and also when I use chrome 1.0.154.59 and IE 7.0.6000.16809. Firefox only shows an hourglass while it loads, Chrome displays the content (without xml tags) while it loads, IE starts displaying the XML tree.

I am accessing http://www.icanget.co.uk/Get_Me_In.xml, not the feeds.perfb.com URL.
0
 
rafique12Author Commented:

The file which I am using to parse the xml is in my original post. I know the xml file loads its the php script which I want to use to write the xml feed into mysql which won't execute.
0
 
rafique12Author Commented:
The script is getmein.php
0
 
rafique12Author Commented:

/getmein.php
0
 
Chris HarteThaumaturgeCommented:
You are just echoing the query.
It should be

$query = "REPLACE INTO ....

then

mysql_query ($query)


See attached code

          if (strlen($product_code) > 0)
            {
                $query = "REPLACE INTO icanget_tickets (product_code, 
                									product_name, 
                									level1, 
                									level2, 
                									description, 
                									buyat_short_deeplink_url, 
                									image_url, 
                									currency, 
                									price, 
                									country, 
                									event_date, 
                									event_venue, 
                									number_available)
 
					  VALUES ('$product_code', 
					  		  '$product_name', 
					  		  '$level1', 
					  		  '$level2', 
					  		  '$description', 
					  		  '$buyat_short_deeplink_url', 
					  		  '$image_url', 
					  		  '$currency', 
					  		  '$price', 
					  		  '$country', 
					  		  '$event_date', 
					  		  '$event_venue', 
					  		  '$number_available')";
               
                $query_run = mysql_query ($query);
                
                if ($query_run == FALSE)
                   die (mysql_error());
                    
                echo $product_name . "has been inserted </br>";
            }

Open in new window

0
 
rafique12Author Commented:
Even with your code I am still get an error message that the page is unavailable...what should I be getting is that the $query was successful?
if (strlen($product_code) > 0)
            {
                $query = "REPLACE INTO icanget_tickets (product_code, 
                                                                                        product_name, 
                                                                                        level1, 
                                                                                        level2, 
                                                                                        description, 
                                                                                        buyat_short_deeplink_url, 
                                                                                        image_url, 
                                                                                        currency, 
                                                                                        price, 
                                                                                        country, 
                                                                                        event_date, 
                                                                                        event_venue, 
                                                                                        number_available)
 
                                          VALUES ('$product_code', 
                                                          '$product_name', 
                                                          '$level1', 
                                                          '$level2', 
                                                          '$description', 
                                                          '$buyat_short_deeplink_url', 
                                                          '$image_url', 
                                                          '$currency', 
                                                          '$price', 
                                                          '$country', 
                                                          '$event_date', 
                                                          '$event_venue', 
                                                          '$number_available')";
               
                $query_run = mysql_query ($query);
                
                if ($query_run == FALSE)
                   die (mysql_error());
                    
                echo $product_name . "has been inserted </br>";
            }
break;
 
}
 
}
 
?>

Open in new window

0
 
rafique12Author Commented:
I have changed the product feed, uploaded it to my server and execute the script but I now get this error
Warning: file_put_contents(Ticketmaster_UK_Hot_-_Tickets.xml) [function.file-put-contents]: failed to open stream: Permission denied in /home/icanget/public_html/getmein.php on line 9
 
Warning: XMLReader::open() [xmlreader.open]: Unable to open source data in /home/icanget/public_html/getmein.php on line 11
 
Warning: XMLReader::read() [xmlreader.read]: Load Data before trying to read in /home/icanget/public_html/getmein.php on line 13

Open in new window

0
 
Chris HarteThaumaturgeCommented:
That means you do not have write persmissions to that directory on the server.
0
 
rafique12Author Commented:

The permissions are 777
0
 
rafique12Author Commented:
I tried parsing the feed on my local host instead of the server and it is working. I configured php.ini to let the script execute for longer than 30 second and all seems to be fine. Thankyou!!
0
All Courses

From novice to tech pro — start learning today.