Files
cinema/file/add/index.php
Francesco Mancuso e831d2b4bf
All checks were successful
Deploy / trigger (push) Successful in 7s
Deploy con DB
2026-04-12 20:10:30 +02:00

140 lines
4.0 KiB
PHP

<?php
if (isset($_GET['s'])) {
highlight_file("index.php");
return;
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Dati inviati
$checks = true;
$nome = "";
$cognome = "";
$data_nascita = "";
// htmlspecialchars effettua una sanitizzazione base
if (isset($_POST['nome'])) {
if ($_POST['nome'] === "" || $_POST['nome'] === null) {
$checks = false;
}
$nome = htmlspecialchars($_POST['nome']);
} else {
$checks = false;
}
if (isset($_POST['cognome'])) {
if ($_POST['cognome'] === "" || $_POST['cognome'] === null) {
$checks = false;
}
$cognome = htmlspecialchars($_POST['cognome']);
} else {
$checks = false;
}
if (isset($_POST['data-nascita'])) {
if ($_POST['data-nascita'] === "" || $_POST['data-nascita'] === null) {
$checks = false;
}
$data_nascita = date("Y-m-d H:i:s", strtotime(htmlspecialchars($_POST['data-nascita'])));
} else {
$checks = false;
}
if (!$checks) {
// Codice HTTP 400: Bad Request
http_response_code(400);
echo '<code>Dati mancanti nella richiesta POST!</code>';
return;
}
$conn = mysqli_connect("localhost", "root", "", "film_attori");
if ($conn === false) {
exit("<code>Errore: impossibile stabilire una connessione " . mysqli_connect_error() . "</code>");
}
//echo "<code>Connesso: " . mysqli_get_host_info($conn) . "</code>";
// Collegamento al DB effettuato, ora facciamo l'inserimento
$insert = "INSERT INTO attori (nome, cognome, data_nascita) VALUES ('" . $nome . "','" . $cognome . "', '" . $data_nascita . "')";
if (mysqli_query($conn, $insert) === false) {
// Codice HTTP 500: Errore
http_response_code(500);
echo "<code>Errore: impossibile eseguire la query. " . mysqli_error($conn) . "</code>";
mysqli_close($conn);
exit();
}
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aggiungi attore - The NoSpace Cinema</title>
<!--- www.francescomancuso.it -->
<link rel="stylesheet" href="../style.css">
</head>
<body>
<header>
<div class="container">
<a href="../" style="text-decoration: none;">
<div>
<img src="../logo.png">
<h4>The NoSpace Cinema</h4>
</div>
</a>
<div>
<a href=".?s" style="font-size:16px">Vedi sorgente pagina</a>
<a href="../search/" class="button">Tutti i film</a>
</div>
</div>
</header>
<div class="container">
<div class="hero">
<h1>Aggiungi attore</h1>
</div>
</div>
<div class="page">
<div class="container">
<?php if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo "<div class=\"message\">Query eseguita con successo!</div>";
} ?>
<form action="." method="POST">
<fieldset>
<label for="nome">Nome</label>
<input type="text" id="nome" name="nome">
</fieldset>
<fieldset>
<label for="cognome">Cognome</label>
<input type="text" id="cognome" name="cognome">
</fieldset>
<fieldset>
<label for="data-nascita">Data di nascita</label>
<input type="date" id="data-nascita" name="data-nascita" max="0">
</fieldset>
<fieldset>
<button type="submit">Invia</button>
</fieldset>
</form>
</div>
</div>
<footer>
<div class="container">
<span>Realizzato da Francesco Giuseppe Mancuso - classe 5E - www.francescomancuso.it</span>
</div>
</footer>
</body>
</html>