I am trying to retrieve filenames that are stored in the database and the actual files stored on my ftp server in a folder and what I am trying to do is display a list of the filenames related to the ticket id and the specific user session but can’t work out how to do it, I am bit new to prepared statements (late to the party on this one I know). My current coding is below. I have been looking on google for examples and looking at php.net etc. but not getting any closed I think
<?php
$mysqli = new mysqli("localhost", "username", "password", "dbname");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
?>
<?php
$stmt = $mysqli->prepare("SELECT support_tickets.ticket_id, support_ticket_files.file_name, support_tickets.user_name FROM support_tickets INNER JOIN support_ticket_files ON support_tickets.user_name=support_ticket_files.user_name
WHERE support_tickets.ticket_id = ? and support_tickets.user_name = '".$_SESSION['user_name']."'");
$stmt->bind_param("iss", $_POST['ticket_id']);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows === 0) exit('No rows');
$stmt->bind_result($ticket_idRow, $filenameRow, $usernameRow);
while($stmt->fetch()) {
$ticket_ids[] = $ticket_idRow;
$filename[] = $filenameRow;
$username[] = $usernameRow;
}
var_export($ticket_ids);
$stmt->close();
?>
<ul class="nav">
<li><a href="support-ticket-images/<?php echo $filename; ?>" class="noline" download="download"><?php echo $filename; ?></a></li>
<?php $stmt->close(); ?>
</ul>
That code just outputs no rows