XML Issue
Posted: Tue May 26, 2009 4:46 am
Hi Lads trying to parse data from xml in to a mysql database i will show you my code so you can get an idea of whats going on, the xml data will be posted to my script.
The Error Message when using this is as follows.
The XML data that needs to be parsed.
If anyone could help it would be great.
Code: Select all
<?php
// XML Gets Posted automatically by text messaging servuce
$post= $_POST['xml'];
$dom = new domDocument;
$dom->loadXML('$post');
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
$sitemap = simplexml_import_dom($dom);
echo $sitemap->originator;
echo "<br>";
echo $sitemap->recipient;
echo "<br>";
echo $sitemap->date;
echo "<br>";
echo $sitemap->message;
echo "<br>";
$originator = $sitemap->originator;
$recipient = $sitemap->recipient;
$date = $sitemap->date;
$message = $sitemap->message;
echo $originator;
echo $recipient;
echo $date;
echo $message;
$con = mysql_connect("db","usr","pw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("anua200_textbookings", $con);
$originator = mysql_real_escape_string($originator);
$recipient = mysql_real_escape_string($recipient);
$date = mysql_real_escape_string($date);
$message = mysql_real_escape_string($message);
$sql="INSERT INTO text_bookings
(
originator,
recipient,
date,
message
)
VALUES
(
'$originator',
'$recipient',
'$date',
'$message'
)";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
echo "Succesfully added data";
}
mysql_close($con);
?>
The Error Message when using this is as follows.
Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Start tag expected, '<' not found in Entity, line: 1 in D:\Domains\cusack.webworld.ie\wwwroot\process2.php on line 5
Warning: simplexml_import_dom() [function.simplexml-import-dom]: Invalid Nodetype to import in D:\Domains\cusack.webworld.ie\wwwroot\process2.php on line 34
The XML data that needs to be parsed.
Code: Select all
<?xml version="1.0" ?>
<sms>
<originator>+353872536719</originator>
<recipient>+353857547357</recipient>
<date>05/21/2009 12:35:38 PM</date>
<message><![CDATA[Yes%20will%20be%20there%20thanks]]></message>
</sms>
If anyone could help it would be great.