Baadier Posted September 7, 2010 Share Posted September 7, 2010 Ive been trying to insert the data pulled from an xml file. Ive got the xml data stored in an array and ive tried to pull each data set and insert but it fails each time on the first attempt. Inputting plain text works as opposed to using the variables. I think the data has special characters in that are causing mySql to fail. This is the code that im using: $dbhost = 'XXXX'; $dbuser = 'XXXX'; $dbpass = 'XXXX'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); if($conn) { echo "Database Connection Successfull...<br /><br />"; } $dbname = 'a4027212_footy'; mysql_select_db($dbname) or die('Couldnt connect to database table'); if($dbname) { echo "Database ".$dbname." Selected..<br /><br />"; } $tweetmeme = "http://api.tweetmeme.com/stories/popular.xml?category=sports-soccer&count=30" ; $xml = @simplexml_load_file($tweetmeme) or die ("no file loaded") ; if($xml) { echo "Tweetmeme XML loaded with ".count($xml->stories->story)." stories in the file..<br /><br />"; } if(get_magic_quotes_gpc()) { echo "Magic Quotes is ON<br /><br />"; } foreach($xml->stories->story as $story) { $title=$story->title; $url=$story->url; $media_type=$story->media_type; $created=$story->created_at; //$current_time=$date(); $url_count=$story->url_count; $comment_count=$story->comment_count; $excerpt=$story->excerpt; $sql = "INSERT INTO ft_tweets (title,url,media_type,created_at,mention_count,comment_count,excerpt) VALUES ($title,$url,$media_type,$created,$url_count,$comment_count,$excerpt)"; $result = mysql_query($sql) or die(mysql_error()); if($result) { echo "added to database<br />"; } } echo "<br /><br />"; ERROR MESSAGES: Database Connection Successfull... Database a4027212_footy Selected.. Tweetmeme XML loaded with 30 stories in the file.. Magic Quotes is ON You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'injury news ahead of Bolton game | News Archive | News | Arsenal.com),http://www' at line 1 PHP version: 5.2.* | MySQL version: 5.0.81-community Quote Link to comment https://forums.phpfreaks.com/topic/212811-insert-data-from-array-not-inserting-rows/ Share on other sites More sharing options...
RussellReal Posted September 8, 2010 Share Posted September 8, 2010 mysql_real_escape_string Quote Link to comment https://forums.phpfreaks.com/topic/212811-insert-data-from-array-not-inserting-rows/#findComment-1108516 Share on other sites More sharing options...
Baadier Posted September 8, 2010 Author Share Posted September 8, 2010 i figured mysql_real_string_escape(), it turns out i was just missing some '' in the actual insert query. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/212811-insert-data-from-array-not-inserting-rows/#findComment-1108518 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.