2

I'm trying to add a new entry to an XML file using SimpleXML

XML structure:

<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 layout:

<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 submit file (what does all the work):

<?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.";
}

?>

I honestly can't think of why this isn't working. I've tried putting the post data into an array in the form of:

$newEvent = array(
'name' => $_POST['name']
etc.

and

$name = $_POST['name']
etc.

To no avail. I've changed the permissions of the files so they're all read/write/execute. I'm almost going to say it might be something to do with the security on the server, but it allows me to easily grab the data so I'm not sure. Any help would be appreciated

  • When you say it isn't working, can you be more specific? Are you getting an error (did you [check your error log / reporting settings](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851)?) – IMSoP Nov 07 '13 at 02:41
  • It's returning a blank screen. I know the form is posting because it's not echoing back the line at the bottom. – Joel Paxton Nov 07 '13 at 02:46
  • 1
    You can't save it to an URL, you need to save it locally. – Paulo Freitas Nov 07 '13 at 02:50
  • That was literally it. Thank you. – Joel Paxton Nov 07 '13 at 02:52
  • For future reference, when you see a blank screen coming back from PHP, it generally means there is a specific error, you just need to know how to find it. Familiarise yourself with the settings described here: http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php/12772851#12772851 If you still don't understand the error you find, you can include it here when asking for help. – IMSoP Nov 07 '13 at 10:11

1 Answers1

0

You don't have any values in your form data so please check your values in your form. I run it in my local server and it works fine. here is your refined form code...

<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>