diff --git a/file/add/index.php b/file/add/index.php index 24e573d..49edec5 100644 --- a/file/add/index.php +++ b/file/add/index.php @@ -50,27 +50,31 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } - $conn = mysqli_connect("localhost", "root", "", "film_attori"); + // Questi valori vengono letti automaticamente + $host = getenv('DB_HOST'); // SarĂ  "local_db" + $db = getenv('DB_NAME'); // SarĂ  "nomerepository-nomeutente" + $user = getenv('DB_USER'); // Uguale al nome DB + $pass = getenv('DB_PASS'); // Password generata casualmente ad ogni deploy + $charset = 'utf8mb4'; - if ($conn === false) { - exit("Errore: impossibile stabilire una connessione " . mysqli_connect_error() . ""); + $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; + + try { + $pdo = new PDO($dsn, $user, $pass); + } catch (\PDOException $e) { + throw new \PDOException($e->getMessage(), (int) $e->getCode()); } - //echo "Connesso: " . mysqli_get_host_info($conn) . ""; - // Collegamento al DB effettuato, ora facciamo l'inserimento - $insert = "INSERT INTO attori (nome, cognome, data_nascita) VALUES ('" . $nome . "','" . $cognome . "', '" . $data_nascita . "')"; + $insert = "INSERT INTO attori (nome, cognome, data_nascita) VALUES (':nome',':cognome', ':data')"; - if (mysqli_query($conn, $insert) === false) { - // Codice HTTP 500: Errore - http_response_code(500); - echo "Errore: impossibile eseguire la query. " . mysqli_error($conn) . ""; - mysqli_close($conn); - exit(); - } - - mysqli_close($conn); + $stmt = $pdo->prepare($insert); + $stmt->execute([ + ':nome' => $nome, + ':cognome' => $cognome, + ':data' => $data_nascita + ]); } ?> diff --git a/file/search/index.php b/file/search/index.php index 4bbd095..5f095c5 100644 --- a/file/search/index.php +++ b/file/search/index.php @@ -27,6 +27,8 @@ $searched = ""; // Leggo la ricerca $params = []; +$query = ""; + if (isset($_GET['q']) && $_GET['q'] !== '') { $nome = $_GET['q']; $searched = $nome;