Php 使用SimpleXML在XML文件中创建新条目
我正在尝试使用SimpleXML向XML文件添加一个新条目 XML结构:Php 使用SimpleXML在XML文件中创建新条目,php,xml,simplexml,Php,Xml,Simplexml,我正在尝试使用SimpleXML向XML文件添加一个新条目 XML结构: <events> <event id="1"> <name>event name</name> <time>09:00</time> <endtime>09:30</endtime> <category>event
<events>
<event id="1">
<name>event name</name>
<time>09:00</time>
<endtime>09:30</endtime>
<category>event category</category>
<description>A description of event</description>
<loc>location of event</loc>
<picturePath>path to picture location</picturePath>
</event>
</events>
及
无济于事。我已经更改了文件的权限,所以它们都是读/写/执行的。我几乎要说,这可能与服务器上的安全性有关,但它允许我轻松获取数据,所以我不确定。如果您的表单数据中没有任何值,请检查表单中的值,我们将不胜感激。我在本地服务器上运行它,它工作正常。这是您的精制表单代码
<form name ="createEvent" method="post" action="createEvent.php">
<input type="hidden" name="check_submit" value="1" />
<table border="1">
<tr bgcolor="#FFA500">
<th>Name</th>
<th>Start Time</th>
<th>End Time</th>
<th>Category</th>
<th>Description</th>
<th>Location</th>
<th>Picture Path</th>
<th>Create</th>
</tr>
<tr>
<td><input type="text" name="name" value="Meghendra" placeholder="Enter new event name..."/></td>
<td><input type="text" name="time" value="15-11-2013" placeholder="Enter event start time..."/></td>
<td><input type="text" name="endtime" value="15-12-2013" placeholder="Enter event end time..."/></td>
<td><input type="text" name="category" value="Demo category"/></td>
<td><input type="text" name="description" value="lorem ipsum is a dummy content." placeholder="Enter a description of the event..."/></td>
<td><input type="text" name="loc" value="florida"/></td>
<td><input type="text" name="picturePath" value="/uploads" placeholder="Enter link to picture..."/></td>
<td><input type="submit" name="create" class="box" value="Create"/></td>
</tr>
</table
</form>
名称
开始时间
结束时间
类别
描述
位置
图片路径
创造
当你说它不起作用时,你能更具体一点吗?您是否收到错误(是吗?)返回一个空白屏幕。我知道表单正在发布,因为它没有回显底部的行。你不能将它保存到URL,你需要将它保存在本地。这就是字面意思。谢谢。作为将来的参考,当你看到一个从PHP返回的空白屏幕时,通常意味着有一个特定的错误,你只需要知道如何找到它。熟悉此处描述的设置:如果您仍然不理解所发现的错误,可以在请求帮助时将其包含在此处。
<?php
if (array_key_exists('check_submit', $_POST)) {
$xml = new SimpleXMLElement ('http://odapp.unsw.adfa.edu.au/~z3370257/joel/practice/events-small.xml', null, true);
$id = count($xml->event);
$add = 1;
$newid = $id + $add;
$event = $xml->addChild('event');
$event->addAttribute('id', $newid);
$event->addChild('name', $_POST['name']);
$event->addChild('time', $_POST['time']);
$event->addChild('endtime', $_POST['endtime']);
$event->addChild('category', $_POST['category']);
$event->addChild('description', $_POST['description']);
$event->addChild('loc', $_POST['loc']);
$event->addChild('picturePath', $_POST['picturePath']);
$xml->asXML('http://odapp.unsw.adfa.edu.au/~z3370257/joel/practice/events-small.xml');
} else {
echo "You can't see this page without submitting the form.";
}
?>
$newEvent = array(
'name' => $_POST['name']
etc.
$name = $_POST['name']
etc.
<form name ="createEvent" method="post" action="createEvent.php">
<input type="hidden" name="check_submit" value="1" />
<table border="1">
<tr bgcolor="#FFA500">
<th>Name</th>
<th>Start Time</th>
<th>End Time</th>
<th>Category</th>
<th>Description</th>
<th>Location</th>
<th>Picture Path</th>
<th>Create</th>
</tr>
<tr>
<td><input type="text" name="name" value="Meghendra" placeholder="Enter new event name..."/></td>
<td><input type="text" name="time" value="15-11-2013" placeholder="Enter event start time..."/></td>
<td><input type="text" name="endtime" value="15-12-2013" placeholder="Enter event end time..."/></td>
<td><input type="text" name="category" value="Demo category"/></td>
<td><input type="text" name="description" value="lorem ipsum is a dummy content." placeholder="Enter a description of the event..."/></td>
<td><input type="text" name="loc" value="florida"/></td>
<td><input type="text" name="picturePath" value="/uploads" placeholder="Enter link to picture..."/></td>
<td><input type="submit" name="create" class="box" value="Create"/></td>
</tr>
</table
</form>