<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="Styles/styles.css">
</head>
<body>
<?php
$LINK = mysqli_connect('127.0.0.1','pisjo950','vjPRjFTxDVIoG7)t','pisjo950');
//get all the extratimes
$statementExtra = $LINK->prepare("SELECT * FROM CineFilms");
$statementExtra->execute();
$resultExtra = $statementExtra->get_result();
if(isset($_POST['submit']))
{
$title = $_POST['title'];
$kdm = $_POST['kdm'];
//insert into CineEntry
$statement = $LINK->prepare("INSERT INTO CineFilms(title, kdm) VALUES (?, ?)");
$statement->bind_param('ss', $title, $kdm);
$statement->execute();
$statement->close();
echo "New Film created successfully";
header("Location: ?Film"); //put this onto the index page instead of loading a new page
}
?>
<form id="form" method="POST">
<br>
<label for="date">Title </label>
<input type="text" name="title">
<br>
<!-- startTime, endTime missing for now -->
<label for="kdm">KDM</label>
<input type="text" name="kdm">
<br>
<button type="submit" name="submit">Submit</button>
</form>
<form action="index.php">
<button type="submit">Back</button>
</form>
<?php
// READ Extras
$films = [];
$stmt = $LINK->prepare("SELECT * FROM CineFilms");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
$films[] = $row;
}
?>
<!-- READ TABLE -->
<h2>All films</h2>
<table border="1" cellpadding="5">
<tr>
<th>ID</th>
<th>Name</th>
<th>Default Time (min)</th>
<th>Actions</th>
</tr>
<?php foreach ($films as $film): ?>
<tr>
<td><?= $film['pk_film'] ?></td>
<td><?= htmlspecialchars($film['title']) ?></td>
<td><?= $film['kdm'] ?></td>
<td>
<a href="?editFilm=<?= $film['pk_film'] ?>">Edit</a> |
<a href="?deleteFilm=<?= $film['pk_film'] ?>" onclick="return confirm('Delete this film?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>