0
votes

I save a XML file content in MySQL database with:

$content = mysql_escape_string($content);
$insert = mysql_query("insert into $db_table_xml (url,content) values ('$url','$content')" ); 
//content type : TEXT in MySQL


simplexml_load_string($content);

it returns an error:

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 361: parser error : AttValue: ' expected in D:\mkw\dev\Web\PHPnow-1.5.6\htdocs\yt2\common.php on line 84

Notice: Trying to get property of non-object in D:\mkw\dev\Web\PHPnow-1.5.6\htdocs\yt2\common.php on line 146

Warning: Invalid argument supplied for foreach() in D:\mkw\dev\Web\PHPnow-1.5.6\htdocs\yt2\common.php on line 146

2
simplexml_load_string($content); is trying to read your escaped content, which turns it into invalid, xml. try to escape the content to insert in your query in a different variable, so you can load the original content in as xml - Ibu

2 Answers

0
votes

This error means it is not valid xml, inspect the xml file to see if there is anything wrong with it.

Look for line 361 in it, there is probably special character or similar error

Edit.

Obviously when you escape the xml, you introduced invalid characters in your xml,

use.

$content_escape = mysql_escape_string($content); 
$insert = mysql_query("insert into $db_table_xml (url,content) values ('$url','$content_escape')" );  //content type : TEXT in MySQL 

now your $contents is not affected

-1
votes

Looks to me like your variable $content contains single quotes that are affecting the termination of the string. This is what your can do if this is the case:

$content= addslashes($content);

Then you write this into your record.