我使用的XML文件显示在谷歌地图的画布标记点,想实现一个网页,我可以将数据输入格式并保存它作为中新的标记我data.xml文件。我试图按照PHP手册,但似乎无法让它工作,所以想知道你是否能够帮助我。表单提交,但似乎没有进入XML文件。我在PHP里面做错了什么?我错过了什么是实际将数据发送到我的XML文件?下面的代码我到目前为止:将表单数据发送到XML
HTML:
<form name="input" action="map.php" method="post">
<p>Name</p>
<input type="text" name="name" placeholder="Name of road/junction"/>
<p>Latitude</p>
<input type="text" name="lat" placeholder="Latitude (should start with 54)"/>
<p>Longitude</p>
<input type="text" name="lng" placeholder="Longitude (should start with -2)"/>
<p>Image</p>
<input type="text" name="img" placeholder="include - images/"/>
<p>Custom Marker</p>
<input type="text" name="custommarker" placeholder="car.png"/>
<p>Description</p>
<input type="text" name="description" placeholder="Description of junction with tips"/>
<input type="submit" value="send"/>
</form>
PHP:
$sxe = new SimpleXMLElement($xmlstr);
$xmldoc->load('../data.xml');
$name = $_POST['name'];
$lat = $_POST['lat'];
$lng = $_POST['lng'];
$img = $_POST['img'];
$custommarker = $_POST['custommarker'];
$description = $_POST['description'];
$root = $xmldoc->firstChild;
$marker = $sxe->addChild('marker');
$root->addAttribute('name', $name);
$root->addAttribute('lat', $lat);
$root->addAttribute('lng', $lng);
$root->addAttribute('img', $img);
$root->addAttribute('custommarker', $custommarker);
$root->addAttribute('description', $description);
echo $sxe->asXML();
$xmldoc->save('../moredata.xml');
然后我的XML布局为如下:
<markers>
<marker name="" lat="" lng="" img="" custommarker="" description "" />
</markers>
你不解释你的代码是如何失败的,以满足您的期望。事实上,你甚至不会提出问题。你能编辑这个问题并解决这个问题吗? –