I'm working on a help ticket project and I have a good portion of it already working except this one aspect. I would like to display all ticket information (from a XML file) to the screen but then be able to append the comments with new comments to the ticket. I print all the ticket information without a problem it's appending it that is the problem. One, because my $_GET array is gone after submit I lose the ticket information, two I can't figure out how to just add new comments to the comments section for the particular ticket in my XML. Below is the code.
<!DOCTYPE html>
<html lang="en">
<head>
<title>
Kapsiak's Ticket Closer
</title>
<meta charset="utf-8">
<link rel="stylesheet" href="site.css">
</head>
<body>
<?php include 'header.php'; ?>
<?php include 'nav.php'; ?>
<main>
<div class="row">
<div class="sidel">
</div>
<main>
<div class="row">
<div class="sidel">
</div>
<div class="main">
<?php
// read all the ticket information to screen
$xml=simplexml_load_file("tickets.xml") or die ("Error: Cannot Display Tickets");
foreach($xml->children() as $ticket) {
if ($ticket['id'] == $_GET['id']) {
echo "<div class='helpLeft'>";
echo "<h3>Requester</h3>";
echo "<p>First Name: " . $ticket->fname . "</p>";
echo "<p>Last Name: " . $ticket->lname . "</p>";
echo "<p>Phone: " . $ticket->phone . "</p>";
echo "<p>School: " . $ticket->loc . "</p>";
echo "<p>Room: " . $ticket->room . "</p>";
echo "</div>";
echo "<div class='helpLeft'>";
echo "<h3>Device Information</h3>";
echo "<p>Device Type: " . $ticket->device . "</p>";
echo "<p>Manufacturer: " . $ticket->manu . "</p>";
echo "<p>Model: " . $ticket->model . "</p>";
echo "<p>Serial: " . $ticket->serial . "</p>";
echo "<p>Status: " . $ticket->status . "</p>";
echo "</div>";
echo "<div class='comments'>";
echo "<h3>Comments</h3>";
// check for new comments
if (!empty($_POST)){
$ticket->appendChild('comments', $_POST(comments));
}
echo "<p>" . $ticket->comments . "</p>";
echo "</div>";
}
}
echo "<br>";
?>
<div class="comments">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<textarea name="comments" id="comments" cols="60" rows="10" required> </textarea><br>
<select size="1" name="status" id="status" required>
<option value="open">Select New Status </option>
<option value="In Progess">In Progress </option>
<option value="Awaiting Reply">Awaiting Reply </option>
<option value="Closed">Closed </option>
</select>
<input type="submit" value="Update"/>
</form>
</div>
</div>
<div class="sider">
</div>
</div>
</main>
<?php include 'footer.php'; ?>
</body>
</html>
<form action="<?php echo $_SERVER['PHP_SELF'] . '?id='. $_GET['id']; ?>" method="POST">So that the$_GET['id']is not empty after submitting the form.$ticket['id'] == $_GET['id']so there has to be a GET-Parameter within the url, but in the form-action the calling url does not contain any GET-Paremeter.$_POST['comments']not$_POST(comments)after that you can iterate over each comment.