The Movie Database Support

Hello

I am brand new to using the TMDB API.

I am using PHP to search for a movie by text and return the results on a web page.

I can successfully search by using IMDB ID with the following code

$key = "REMOVED"
$query = $_POST["filename"];

$json = file_get_contents("https://api.themoviedb.org/3/movie/$query?api_key=$key");

$result = json_decode($json, true);

$poster_path = $result["poster_path"];
$backdrop_path = $result["backdrop_path"];
$overview = $result["overview"];

echo '
<div id="item" style="width: 90%;">
    <div id="title">
        '.$result["title"].'
    </div>
    <div id="right">
        <div id="poster" style="float: left; width: 20%;">
            <img src="https://image.tmdb.org/t/p/w500'.$poster_path.'" style="width: 100px; height: auto;">
        </div>
        <div id="overview" style="float: left; width: 80%;">
            '.$result["overview"].'
        </div>
    </div>
</div>
';



}
?>

<div>
<form id="search" method="post" action="ajax_calls.php">
Film: <input type="text" id="filename" name="filename" />
<input type="submit" value="Search" />
</form>
</div>

But when I replace the API URL with:

https://api.themoviedb.org/3/search/movie?api_key=$key&query=Jack+Reacher

It returns no results. Using that URL to directly query the API via a web browser returns an array as expected.

Can anyone point me in the right direction as to where I'm going wrong?

Thanks

2 replies (on page 1 of 1)

Jump to last post

That should work to my eyes. Could you upload a full sample of your code to github or somewhere (without your key obviously) so I can see where the issue is?

also to the mods: should I be able to see that form input box? you might want to fix that!

Oh ok now the code markup has been clarified there are a number of mistakes there.

There is no semicolon after $key = "REMOVED"

The api call should be https://api.themoviedb.org/3/search/movie?query= $query&api_key=$key

and there's a trailing curly bracket on line 30 that shouldn't be there.

Edit: It also seems that the file_get_contents PHP function doesn't like ampersands (&), so I suggest using a workaround or simply using curl (Client URL function) instead.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login