A - Search
Create a webpage that will retrieve all the data stored in the movies database table and display the formatted results.
Task
Create the two pages below.
<html>
<head>
</head>
<body>
<h1>Movie Website</h1>
<form action="display_movies.php" method="POST">
<input type="submit" value="Display all movies">
</form>
</body>
</html>
<html>
<head>
</head>
<body>
<h1>Movie Website</h1>
<a href="home.html">Back</a>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "movies";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn){
die("Connection failed");
};
$sql = "SELECT * FROM movies";
$result = mysqli_query($conn, $sql);
echo "<p>There are ".mysqli_num_rows($result)." movies.</p>";
if(mysqli_num_rows($result) > 0){
echo "<table>";
echo "<tr> <th>ID</th> <th>Title</th> <th>Genre</th> <th>Release Date</th> </tr>";
while($row = mysqli_fetch_array($result)){
echo "<tr>
<td>".$row["id"]."</td>
<td>".$row["title"]."</td>
<td>".$row["genre"]."</td>
<td>".$row["release_date"]."</td>
</tr>";
}
echo "</table>";
}
mysqli_close($conn);
?>
</body>
</html>
CREATE DATABASE Movies;
USE Movies;
CREATE TABLE Movies (
id INT PRIMARY KEY,
title VARCHAR(100),
genre VARCHAR(50),
release_date DATE
);
INSERT INTO Movies (id, title, genre, release_date) VALUES (1, 'Toy Story', 'Animation', '1995-11-22'), (2, 'The Lion King', 'Animation', '1994-06-24'), (3, 'Jurassic Park', 'Adventure', '1993-07-16'), (4, 'Titanic', 'Romance', '1997-12-19'), (5, 'The Matrix', 'Science Fiction', '1999-03-31'), (6, 'Avatar', 'Science Fiction', '2009-12-18'), (7, 'Frozen', 'Animation', '2013-11-27'), (8, 'Shrek', 'Animation', '2001-05-18'), (9, 'Jumanji', 'Adventure', '1995-12-15'), (10, 'The Incredibles', 'Animation', '2004-11-05'), (11, 'Finding Nemo', 'Animation', '2003-05-30'), (12, 'The Dark Knight', 'Action', '2008-07-18'), (13, 'Iron Man', 'Action', '2008-05-02'), (14, 'Black Panther', 'Action', '2018-02-16'), (15, 'Avengers Endgame', 'Action', '2019-04-26'), (16, 'Spider Man', 'Action', '2002-07-03'), (17, 'Harry Potter and the Philosophers Stone', 'Fantasy', '2001-11-16'), (18, 'The Hobbit', 'Fantasy', '2012-12-14'), (19, 'The Lord of the Rings', 'Fantasy', '2001-12-19'), (20, 'Pirates of the Caribbean', 'Adventure', '2003-07-09'), (21, 'Back to the Future', 'Science Fiction', '1985-07-03'), (22, 'E.T.', 'Science Fiction', '1982-06-11'), (23, 'Ghostbusters', 'Comedy', '1984-06-08'), (24, 'Home Alone', 'Comedy', '1990-11-16'), (25, 'Mrs Doubtfire', 'Comedy', '1993-11-24'), (26, 'The Mask', 'Comedy', '1994-07-29'), (27, 'Men in Black', 'Science Fiction', '1997-07-02'), (28, 'Independence Day', 'Science Fiction', '1996-07-03'), (29, 'Top Gun', 'Action', '1986-05-16'), (30, 'Rocky', 'Sport', '1976-12-03'), (31, 'Creed', 'Sport', '2015-11-25'), (32, 'Forrest Gump', 'Drama', '1994-07-06'), (33, 'The Green Mile', 'Drama', '1999-12-10'), (34, 'The Shawshank Redemption', 'Drama', '1994-09-23'), (35, 'Gladiator', 'Action', '2000-05-05'), (36, 'Braveheart', 'Drama', '1995-05-18'), (37, 'Interstellar', 'Science Fiction', '2014-11-07'), (38, 'Inception', 'Science Fiction', '2010-07-16'), (39, 'The Martian', 'Science Fiction', '2015-09-30'), (40, 'Wall E', 'Animation', '2008-06-27'), (41, 'Up', 'Animation', '2009-05-29'), (42, 'Ratatouille', 'Animation', '2007-06-29'), (43, 'Moana', 'Animation', '2016-11-23'), (44, 'Coco', 'Animation', '2017-11-22'), (45, 'Wonder Woman', 'Action', '2017-06-02'), (46, 'Superman', 'Action', '1978-12-15'), (47, 'The Batman', 'Action', '2022-03-04'), (48, 'Paddington', 'Comedy', '2014-11-28'), (49, 'Wonka', 'Fantasy', '2023-12-08'), (50, 'Inside Out', 'Animation', '2015-06-19');
td{
border: solid 1px black;
}