Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user = 'root';
- $password = 'coderslab';
- $dbname = 'cinemas_ex';
- $connection = new PDO("mysql:host=localhost;dbname=" . $dbname, $user, $password);
- if ($connection->errorCode() != null) {
- var_dump($connection->errorInfo());
- die();
- }
- if ($_SERVER["REQUEST_METHOD"] === "GET" && isset($_GET['id'])) {
- $query = "SELECT * FROM Movies WHERE id=" . $_GET['id'];
- $result = $connection->query($query);
- $movie = $result->fetch(PDO::FETCH_ASSOC);
- $id = $movie['id'];
- $name = $movie['name'];
- $description = $movie['description'];
- $rating = $movie['rating'];
- } elseif ($_SERVER["REQUEST_METHOD"] === "POST") {
- // echo $_POST['movieId'], $_POST['movieName'], $_POST['movieDescription'], $_POST['movieRating'];
- $movieId = $_POST['movieId'];
- $movieName = $_POST['movieName'];
- $movieDescription = $_POST['movieDescription'];
- $movieRating = $_POST['movieRating'];
- $query = "UPDATE Movies SET name=:name description=:description rating=:rating WHERE id=:id";
- try {
- $stmt = $connection->prepare($query);
- $stmt->execute(['name' => $movieName,
- 'description' => $movieDescription,
- 'rating' => $movieRating,
- 'id' => $movieId]);
- echo "Wpis zostaล zaktualizowany.";
- } catch (PDOException $e) {
- echo "Blad: " . $e->getMessage();
- }
- die();
- } else {
- echo "Zly imput";
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport"
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Zadanie 1 - edycja filmu</title>
- <!-- Latest compiled and minified CSS -->
- <link rel="stylesheet" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- </head>
- <body>
- <div class="container">
- <div class="row">
- <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
- </div>
- <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
- <form action="" method="post" role="form">
- <legend>Edycja filmu</legend>
- <div class="form-group">
- <label for="">Id filmu</label>
- <input type="text" class="form-control" readonly name="movieId" id="movieId" placeholder="Id filmu"
- value="<?= $id ?>">
- </div>
- <div class="form-group">
- <label for="">Nazwa filmu</label>
- <input type="text" class="form-control" name="movieName" id="movieName" placeholder="Nazwa filmu"
- value="<?= $name ?>">
- </div>
- <div class="form-group">
- <label for="">Opis filmu</label>
- <input type="text" class="form-control" name="movieDescription" id="movieDescription"
- placeholder="Opis filmu"
- value="<?= $description ?>">
- </div>
- <div class="form-group">
- <label for="">Rating filmu</label>
- <input type="number" step="0.01" class="form-control" name="movieRating" id="movieRating"
- placeholder="Rating filmu"
- value="<?= $rating ?>">
- </div>
- <button type="submit" class="btn btn-primary">Edytuj</button>
- </form>
- </div>
- <div class="col-xs-4 col-sm-4 col-md-4 col-lg-4">
- </div>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement