Question : Cannot insert xml in mysql

I would like to insert an xml into a mysql table field.
I use the attached code and a table field of blob or
of varchar. However, nothing is inserted into the table.
How can I fix this?
$xml = simplexml_load_string(stripslashes($_POST['xml']));  
$querystring = "INSERT INTO MYTABLE(xml) VALUES ('$xml')";

Answer : Cannot insert xml in mysql

Remember that varchar normally limits to 255 characters although MySQL has alrger VARCHAR options available. Personally I would probably use a MEDIUMTEXT field to store the XML as it gives me up to 16MB of data.

To convert the XML from an object to a string use the ->asXML method or just store it directly from your $_POST data

$querystring = "INSERT INTO MYTABLE(xml) VALUES ('{$_POST['xml']}')";


$querystring = "INSERT INTO MYTABLE(xml) VALUES ('{$xml->asXml()}')";
Random Solutions  
programming4us programming4us