2

SimpleXML を使用して XML ファイルに新しいエントリを追加しようとしています

XML 構造:

<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" placeholder="Enter new event name..."/></td>
            <td><input type="text" name="time" placeholder="Enter event start time..."/></td>
            <td><input type="text" name="endtime" placeholder="Enter event end time..."/></td>
            <td><input type="text" name="category"/></td>
            <td><input type="text" name="description" placeholder="Enter a description of the event..."/></td>
            <td><input type="text" name="loc"/></td>
            <td><input type="text" name="picturePath" placeholder="Enter link to picture..."/></td>
            <td><input type="submit" name="create" class="box" value="Create"/></td>
        </tr>
        </table
        </form>

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.

無駄に。ファイルのアクセス許可を変更して、すべて読み取り/書き込み/実行できるようにしました。サーバーのセキュリティに関係している可能性があると言いたいのですが、データを簡単に取得できるのでよくわかりません。どんな助けでもいただければ幸いです

4

1 に答える 1

0

フォーム データに値がないため、フォームの値を確認してください。ローカルサーバーで実行しましたが、正常に動作します。ここにあなたの洗練されたフォームコードがあります...

<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>
于 2013-11-15T14:44:30.547 に答える