Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = "localhost";
- $user = "root";
- $pass = "coderslab";
- $db = "cinemas_ex";
- if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- if (isset($_POST['name']) && isset($_POST['address'])) {
- $name = trim($_POST['name']);
- $address = trim($_POST['address']);
- try {
- $conn = new PDO(
- "mysql:host=$host;dbname=$db;charset=UTF8",
- $user,
- $pass,
- [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ]
- );
- $sqlCinemas = "INSERT INTO Cinemas(name, address)
- VALUES (:name, :address)";
- $stmt = $conn->prepare($sqlCinemas);
- $stmt->execute([
- 'name' => $name,
- 'address' => $address,
- ]);
- echo 'Nowe kino w bazie';
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- elseif (isset($_POST['name']) && isset($_POST['description']) && isset($_POST['rating'])){
- $name = trim($_POST['name']);
- $description = trim($_POST['description']);
- $rating = trim($_POST['rating']);
- try {
- $conn = new PDO(
- "mysql:host=$host;dbname=$db;charset=UTF8",
- $user,
- $pass,
- [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ]
- );
- $sqlMovies = "INSERT INTO Movies(name, description, rating)
- VALUES (:name, :description, :rating)";
- $stmt = $conn->prepare($sqlMovies);
- $stmt->execute([
- 'name' => $name,
- 'description' => $description,
- 'rating' => $rating,
- ]);
- echo 'Nowy film w bazie';
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- elseif (isset($_POST['quantity']) && isset($_POST['price'])){
- $quantity = trim($_POST['quantity']);
- $price = trim($_POST['price']);
- try {
- $conn = new PDO(
- "mysql:host=$host;dbname=$db;charset=UTF8",
- $user,
- $pass,
- [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ]
- );
- $sqlTickets = "INSERT INTO Tickets(quantity, price)
- VALUES (:quantity, :price)";
- $stmt = $conn->prepare($sqlTickets);
- $stmt->execute([
- 'quantity' => $quantity,
- 'price' => $price,
- ]);
- echo 'Nowe bilety w bazie';
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- elseif (isset($_POST['type']) && isset($_POST['date'])){
- $type = trim($_POST['type']);
- $date = trim($_POST['date']);
- try {
- $conn = new PDO(
- "mysql:host=$host;dbname=$db;charset=UTF8",
- $user,
- $pass,
- [
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- ]
- );
- $sqlPayments = "INSERT INTO Payments(type, date)
- VALUES (:type, :date)";
- $stmt = $conn->prepare($sqlPayments);
- $stmt->execute([
- 'type' => $type,
- 'date' => $date,
- ]);
- echo 'Nowa pลatnoลฤ w bazie';
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement