Ok so,
I have been trying to make a ticket system for my wxPanel in order to provide basic support for the application. Although I am easily able to make a database record with the provided code:
PHP:
if (isset($_POST['submit'])) {
$subject = $_POST['subject'];
$message = $_POST['message'];
$date = date('D M H:i');
$subject = mysqli_real_escape_string($subject);
$message = mysqli_real_escape_string($message);
$ticket_id = 'TICK_'.rand(00000,99999);
if (strlen($subject) === 0) {
echo "Subject Invalid.";
} elseif (strlen($message) === 0) {
echo "Message Invalid.";
} else {
mysqli_query("INSERT INTO tickets VALUES(
NULL,
'".$ticket_id."',
'".$_SESSION['user']."',
'".$subject."',
'1',
'".$date."',
'".$message."'
)");
}
header('Location: /view-ticket?identifier='.$ticket_id);
}
Works fine... Then there is this, which is ment to fetch the ticket records and display the titles one by one:
PHP:
$query = mysqli_query("SELECT `subject`,`ticket_id` FROM tickets WHERE `username` = '".$_SESSION['user']."'");
while ($row = mysqli_fetch_assoc($query)) {
$tickets = $row['subject'];
$id = $row['ticket_id'];
}
foreach ($tickets as $ticket) {
echo '
<a href="view-ticket?identifier='.$id.'"><h2>'.$ticket.'</h2></a>
';
}
This always returns NULL. And also none of this works either:
if (isset($_GET['identifier']) === false || empty($_GET['identifier']) === true) {
header('Location: /tickets');
exit();
}
$id = mysqli_real_escape_string($_GET['identifier']);
$query = mysqli_query("SELECT `ticket_id`,`message`,`timestamp`,`status` FROM tickets WHERE `ticket_id` = '".$id."'");
while($row = mysqli_fetch_assoc($query)) {
$ticket_id = $row['ticket_id'];
$message = $row['message'];
$timestamp = $row['timestamp'];
$status = $row['status'];
}
foreach($message as $msg) {
echo '
<div class="ticket-message">
<h2>'.$message.'</h2>
</div>';
}
Thank you in advance!
p.s. Some of my code may be messy. Advice is always appreciated :)