Browse Source

Primer Commit

master
janmaroto 2 months ago
commit
326e779d06
  1. 45
      data_submit.php
  2. 0
      index.html
  3. 32
      index.php

45
data_submit.php

@ -0,0 +1,45 @@
<?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;
?>

0
index.html

32
index.php

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<body>
<h2>Fill the input fields to interact</h2>
<form action="./data_submit.php" method="post">
<label for="filmid">Film ID</label><br>
<input type="text" id="filmid" name="filmid"><br>
<label for="ftitle">Film Title</label><br>
<input type="text" id="ftitle" name="ftitle"><br>
<label for="fyear">Film Year</label><br>
<input type="text" id="fyear" name="fyear"><br><br>
<label for="foption">Operation</label><br><br>
<select id="foption" name="foption">
<option value="choose" selected>Choose</option>
<option value="select">Select</option>
<option value="insert">Insert</option>
<option value="delete">Delete</option>
<option value="update">Update</option>
</select><br><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
if (isset($_GET["message"])){
echo $_GET["message"];
}
?>
Loading…
Cancel
Save