Hello I have been trying a lot of loading xml via php but from my vps error log I always got error.
PHP Warning: Invalid argument supplied for foreach() Trying to get property of non-object
So far this what I have created
xml.php <?php $url = "test.xml"; $ch = curl_init(); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec ($ch); curl_close($ch); $xml = simplexml_load_string($data); $con = mysql_connect("localhost","root","mypassw0rd"); mysql_select_db("test_xml",$con) or die(mysql_error()); foreach($xml -> item as $row){ $title = $row -> title; $destination = $row -> destination; $price = $row -> price; mysql_query("INSERT INTO `tblxml` VALUES('NULL','$title','$destination','$price')") or die(mysql_error()); } ?> test.xml
<item> <title> title 1 </title> <destination> destination 1 </destination> <price> price 1 </price> </item> table structure
CREATE TABLE IF NOT EXISTS `tblxml` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` text NOT NULL, `destination` text NOT NULL, `price` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; xml and php both on the same folder.
Any help would appreciate.
No comments:
Post a Comment