function aggiornaDB($azione = "")
{
global $row, $message;
switch ($azione)
{
case "inserisci":
$sql = "INSERT INTO film(movie_title, also_known, year, minutes, distributor, studio, release_data, incollection, synopsis) VALUES ("
. " '" . $row['movie_title'] . "'"
. ", '" . $row['also_known'] . "'"
. ", '" . $row['year'] . "'"
. ", '" . $row['minutes'] . "'"
. ", '" . $row['distributor'] . "'"
. ", '" . $row['studio'] . "'"
. ", '" . $row['release_data'] . "'"
. ", '" . $row['incollection'] . "'"
. ", '" . $row['synopsis'] . "'"
. " )";
break;
case "modifica":
$sql = "UPDATE film SET"
. " movie_title='" . $row['movie_title'] . "'"
. ", also_known='" . $row['also_known'] . "'"
. ", year='" . $row['year'] . "'"
. ", minutes='" . $row['minutes'] . "'"
. ", distributor='" . $row['distributor'] . "'"
. ", studio='" . $row['studio'] . "'"
. ", release_data='" . $row['release_data'] . "'"
. ", incollection='" . $row['incollection'] . "'"
. ", synopsis='" . $row['synopsis'] . "'"
. " WHERE film_id='" . $row['film_id'] . "'";
break;
case "elimina":
$sql = "DELETE FROM film"
. " WHERE film_id='" . $row['film_id']. "'";
break;
case "cerca":
$sql = "SELECT film_id, movie_title, also_known, year, minutes, distributor, studio, release_data, incollection, synopsis"
. " FROM film WHERE film_id='" . $row['film_id'] . "'";
break;
default:
$message = "ERRORE : aggiornaDB, azione non riconosciuta";
return;
break;
}
echo $sql . "<br />"; error_log($sql, 0);
$servername = "localhost";
$username = "exadmin";
$password = "expass";
$dbname = "xxx";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_errno) { $message = "ERRORE : connessione al db fallita, " . $conn->connect_error; return; }
$result = $conn->query($sql);
if ( !$result ) { $message = "ERRORE : aggiornaDB, errore nella query, " . $conn->error; return; }
if ($azione == "cerca")
{
$row = $result->fetch_assoc(); $result->free();
}
else
{
inizializzaVariabili();
$message = "Congratulazioni, il database é stato aggiornato.";
}
$conn->close();
}