Advertisement
Guest User

Untitled

a guest
Apr 13th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.64 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "localhost";
  4. $user = "root";
  5. $pass = "coderslab";
  6. $db = "cinemas_ex";
  7.  
  8. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  9.     if (isset($_POST['name']) && isset($_POST['address'])) {
  10.  
  11.  
  12.         $name = trim($_POST['name']);
  13.         $address = trim($_POST['address']);
  14.  
  15.         try {
  16.             $conn = new PDO(
  17.                 "mysql:host=$host;dbname=$db;charset=UTF8",
  18.                 $user,
  19.                 $pass,
  20.                 [
  21.                     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  22.                 ]
  23.             );
  24.  
  25.             $sqlCinemas = "INSERT INTO Cinemas(name, address)
  26.                      VALUES (:name, :address)";
  27.  
  28.  
  29.             $stmt = $conn->prepare($sqlCinemas);
  30.  
  31.             $stmt->execute([
  32.                 'name' => $name,
  33.                 'address' => $address,
  34.             ]);
  35.  
  36.             echo 'Nowe kino w bazie';
  37.  
  38.         } catch (PDOException $e) {
  39.             echo $e->getMessage();
  40.         }
  41.     }
  42.  
  43.     elseif (isset($_POST['name']) && isset($_POST['description']) && isset($_POST['rating'])){
  44.  
  45.         $name = trim($_POST['name']);
  46.         $description = trim($_POST['description']);
  47.         $rating = trim($_POST['rating']);
  48.  
  49.         try {
  50.             $conn = new PDO(
  51.                 "mysql:host=$host;dbname=$db;charset=UTF8",
  52.                 $user,
  53.                 $pass,
  54.                 [
  55.                     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  56.                 ]
  57.             );
  58.  
  59.  
  60.  
  61.             $sqlMovies = "INSERT INTO Movies(name, description, rating)
  62.                      VALUES (:name, :description, :rating)";
  63.  
  64.  
  65.  
  66.             $stmt = $conn->prepare($sqlMovies);
  67.  
  68.             $stmt->execute([
  69.                 'name' => $name,
  70.                 'description' => $description,
  71.                 'rating' => $rating,
  72.             ]);
  73.  
  74.             echo 'Nowy film w bazie';
  75.  
  76.         } catch (PDOException $e) {
  77.             echo $e->getMessage();
  78.         }
  79.     }
  80.  
  81.     elseif (isset($_POST['quantity']) && isset($_POST['price'])){
  82.  
  83.         $quantity = trim($_POST['quantity']);
  84.         $price = trim($_POST['price']);
  85.  
  86.         try {
  87.             $conn = new PDO(
  88.                 "mysql:host=$host;dbname=$db;charset=UTF8",
  89.                 $user,
  90.                 $pass,
  91.                 [
  92.                     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  93.                 ]
  94.             );
  95.  
  96.  
  97.             $sqlTickets = "INSERT INTO Tickets(quantity, price)
  98.                      VALUES (:quantity, :price)";
  99.  
  100.  
  101.             $stmt = $conn->prepare($sqlTickets);
  102.  
  103.             $stmt->execute([
  104.                 'quantity' => $quantity,
  105.                 'price' => $price,
  106.             ]);
  107.  
  108.             echo 'Nowe bilety w bazie';
  109.  
  110.         } catch (PDOException $e) {
  111.             echo $e->getMessage();
  112.         }
  113.  
  114.     }
  115.  
  116.     elseif (isset($_POST['type']) && isset($_POST['date'])){
  117.  
  118.         $type = trim($_POST['type']);
  119.         $date = trim($_POST['date']);
  120.  
  121.         try {
  122.             $conn = new PDO(
  123.                 "mysql:host=$host;dbname=$db;charset=UTF8",
  124.                 $user,
  125.                 $pass,
  126.                 [
  127.                     PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
  128.                 ]
  129.             );
  130.  
  131.  
  132.             $sqlPayments = "INSERT INTO Payments(type, date)
  133.                      VALUES (:type, :date)";
  134.  
  135.             $stmt = $conn->prepare($sqlPayments);
  136.  
  137.             $stmt->execute([
  138.                 'type' => $type,
  139.                 'date' => $date,
  140.             ]);
  141.  
  142.             echo 'Nowa pล‚atnoล›ฤ‡ w bazie';
  143.  
  144.         } catch (PDOException $e) {
  145.             echo $e->getMessage();
  146.         }
  147.  
  148.     }
  149.  
  150. }
  151.  
  152. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement