Table of Contents
Introduction: Why Build a PHP Movie Search App?
A Simple Movie Search Using PHP is a fun and practical way to learn how to work with real-world APIs. In this project, we’ll use the free The Movie Database (TMDb) API to fetch movie titles, posters, and details.
Older tutorials relied on jQuery AJAX, but in 2025 we’ll do things the modern way — with PHP 8 for the backend and vanilla JavaScript fetch() for the frontend.
By the end of this tutorial, you’ll have a working app that lets users search for movies and instantly see results with posters, titles, and overviews.
Prerequisites for Building a Movie Search Using PHP
Before we begin, make sure you have:
- PHP 8+ installed locally or on your hosting
- A free TMDb API key
/movie-search
├── index.html
├── search.php
└── style.cssFrontend Code: index.html with JavaScript Fetch
This is the user interface of our PHP movie search app. It includes an input field, a results section, and a script that calls our PHP backend with fetch().
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PHP Movie Search App (TMDb API)</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>PHP Movie Search App</h1>
<input type="text" id="searchInput" placeholder="Type a movie title...">
<div id="results"></div>
</div>
<script>
const input = document.getElementById('searchInput');
const results = document.getElementById('results');
input.addEventListener('keyup', async () => {
const query = input.value.trim();
if (query.length < 2) {
results.innerHTML = "";
return;
}
const res = await fetch(`search.php?q=${encodeURIComponent(query)}`);
const movies = await res.json();
results.innerHTML = movies.map(movie => `
<div class="movie">
<img src="https://image.tmdb.org/t/p/w200${movie.poster_path}" alt="">
<h3>${movie.title} (${movie.release_date?.slice(0,4) || "N/A"})</h3>
<p>${movie.overview.slice(0,100)}...</p>
</div>
`).join('');
});
</script>
</body>
</html>Backend Code: search.php for TMDb API Calls
This PHP file handles the TMDb API requests and returns results in JSON format to our frontend.
<?php
header('Content-Type: application/json');
$apiKey = "YOUR_TMDB_API_KEY";
$query = isset($_GET['q']) ? urlencode($_GET['q']) : '';
if (!$query) {
echo json_encode([]);
exit;
}
$url = "https://api.themoviedb.org/3/search/movie?api_key=$apiKey&language=en-US&query=$query&page=1&include_adult=false";
$response = file_get_contents($url);
if ($response === FALSE) {
echo json_encode(["error" => "API request failed"]);
exit;
}
$data = json_decode($response, true);
// Return just results
echo json_encode($data['results']);
Styling the PHP Movie Search App (style.css)
Here’s some basic CSS to style the results grid of your movie search application.
body {
font-family: Arial, sans-serif;
background: #f7f7f7;
}
.container {
max-width: 800px;
margin: 50px auto;
text-align: center;
}
#searchInput {
width: 100%;
padding: 10px;
margin-bottom: 20px;
}
.movie {
background: #fff;
margin: 10px;
padding: 15px;
border-radius: 6px;
display: flex;
align-items: flex-start;
gap: 15px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.movie img {
width: 100px;
border-radius: 4px;
}
.movie h3 {
margin: 0;
}
Why Use PHP 8 + Fetch Instead of jQuery AJAX?
- ✅ Modern JavaScript –
fetch()is promise-based, cleaner, and widely supported. - ✅ Lightweight – no need to load the jQuery library.
- ✅ Better readability – easier to follow the flow of requests.
- ✅ Future-proof – works natively in all modern browsers.
Enhancements for the PHP Movie Search App
Once you have the basics running, you can extend this PHP movie app with features like:
- Pagination or a “Load More” button
- Autocomplete dropdown while typing
- Movie detail pages with cast and trailers
- A favorites list using localStorage or a database
Conclusion: Build Your Own Movie Search with PHP Today
With just a few lines of code, you now have a fully functional PHP Movie Search App powered by the TMDb API. This project is perfect for beginners who want to practice working with APIs in PHP and modern JavaScript.
From here, you can customize the UI, expand the features, and even integrate it into larger projects.
The best part? The Movie Database API is free to use, making it the perfect playground for learning how to fetch and display external data in PHP.