Projecte M07, botiga en php.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.4 KiB

<?php
$filmId=$_POST['filmid'];
$fTitle=$_POST['ftitle'];
$fYear=$_POST['fyear'];
$inputOption=$_POST['foption'];
// echo $filmId . $fTitle . $fYear . $inputOption;
//Connexió
$con =new mysqli('localhost','jan','jan','pelis');
//Consulta
switch ($inputOption) {
case 'select':
$sql = "SELECT * FROM PELICULA WHERE ID = '$filmId'";
break;
case 'insert':
$sql = "INSERT INTO PELICULA(ID, TITULO, ANYO) VALUES ('$filmId', '$fTitle', '$fYear')";
break;
case 'delete':
$sql = "DELETE FROM PELICULA WHERE ID = '$filmId'";
break;
case 'update':
$sql = "UPDATE PELICULA SET TITULO = '$fTitle', ANYO = '$fYear' WHERE ID='$filmId'";
break;
default:
$output = "You gotta choose an option ";
break;
}
if ($inputOption !== "choose") {
$rs = $con->query($sql);
if ($inputOption === "select") {
$row = $rs->fetch_array();
$output = "Result Set: " . $row[0] . ", " . $row[1] . ", " . $row[2] . ", " . $row[3] . ", " . $row[4];
} else if ($rs === TRUE) {
$output = "Result Set: Successfull transaction";
} else {
$output = "Result Set: Transaction error: " . $sql . "<br>" . $con->error;
};
}
header("Location: ./index.php?message=$output");
// echo $output;
?>