Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php
  2. $user = 'root';
  3. $password = 'coderslab';
  4. $dbname = 'cinemas_ex';
  5.  
  6. $connection = new PDO("mysql:host=localhost;dbname=" . $dbname, $user, $password);
  7.  
  8. if ($connection->errorCode() != null) {
  9. var_dump($connection->errorInfo());
  10. die();
  11. }
  12. if ($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET['id'])) {
  13. $query = "SELECT * FROM Movies WHERE id=" . $_GET['id'];
  14. $result = $connection->query($query);
  15. $movie = $result->fetch(PDO::FETCH_ASSOC);
  16.  
  17. $id = $movie['id'];
  18. $name = $movie['name'];
  19. $description = $movie['description'];
  20. $rating = $movie['rating'];
  21. } elseif ($_SERVER["REQUEST_METHOD"] === "POST") {
  22. // echo $_POST['movieId'], $_POST['movieName'], $_POST['movieDescription'], $_POST['movieRating'];
  23. $movieId = $_POST['movieId'];
  24. $movieName = $_POST['movieName'];
  25. $movieDescription = $_POST['movieDescription'];
  26. $movieRating = $_POST['movieRating'];
  27.  
  28. $query = "UPDATE Movies SET name=:name description=:description rating=:rating WHERE id=:id";
  29.  
  30. try {
  31. $stmt = $connection->prepare($query);
  32. $stmt->execute(['name' => $movieName,
  33. 'description' => $movieDescription,
  34. 'rating' => $movieRating,
  35. 'id' => $movieId]);
  36. echo "Wpis zostaล‚ zaktualizowany.";
  37. } catch (PDOException $e) {
  38. echo "Blad: " . $e->getMessage();
  39. }
  40. die();
  41. } else {
  42. echo "Zly imput";
  43. }
  44. ?>
  45. <!doctype html>
  46. <html lang="en">
  47. <head>
  48. <meta charset="UTF-8">
  49. <meta name="viewport"
  50. content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  51. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  52. <title>Zadanie 1 - edycja filmu</title>
  53. <!-- Latest compiled and minified CSS -->
  54. <link rel="stylesheet" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  55. </head>
  56. <body>
  57. <div class="container">
  58. <div class="row">
  59. <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
  60.  
  61. </div>
  62. <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
  63. <form action="" method="post" role="form">
  64. <legend>Edycja filmu</legend>
  65. <div class="form-group">
  66. <label for="">Id filmu</label>
  67. <input type="text" class="form-control" readonly name="movieId" id="movieId" placeholder="Id filmu"
  68. value="<?= $id ?>">
  69. </div>
  70. <div class="form-group">
  71. <label for="">Nazwa filmu</label>
  72. <input type="text" class="form-control" name="movieName" id="movieName" placeholder="Nazwa filmu"
  73. value="<?= $name ?>">
  74. </div>
  75. <div class="form-group">
  76. <label for="">Opis filmu</label>
  77. <input type="text" class="form-control" name="movieDescription" id="movieDescription"
  78. placeholder="Opis filmu"
  79. value="<?= $description ?>">
  80. </div>
  81. <div class="form-group">
  82. <label for="">Rating filmu</label>
  83. <input type="number" step="0.01" class="form-control" name="movieRating" id="movieRating"
  84. placeholder="Rating filmu"
  85. value="<?= $rating ?>">
  86. </div>
  87. <button type="submit" class="btn btn-primary">Edytuj</button>
  88. </form>
  89. </div>
  90. <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
  91.  
  92. </div>
  93. </div>
  94. </div>
  95. </body>
  96. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement