Exemplo n.º 1
0
}
// If actor is not a string then tell the user that is the case
if (isset($_POST['submit']) && $_SESSION['actor'] != '' && !is_string($_SESSION['actor'])) {
    exit('<div class="error">Actor names must be strings</div>');
}
// If nothing is entered tell the user
if (isset($_POST['submit']) && $_SESSION['title'] == '' && $_SESSION['director'] == '' && $_SESSION['actor'] == '') {
    exit('<div class="error">Enter something to search in at least one field</div>');
}
// With validation complete set each of the parameters and submit a search query
$search = new NetflixSearch();
if ($_SESSION['title'] != '') {
    $search->setTitle($_SESSION['title']);
}
if ($_SESSION['director'] != '') {
    $search->setDirector($_SESSION['director']);
}
if ($_SESSION['actor'] != '') {
    $search->setActor($_SESSION['actor']);
}
// Use a try statement to make sure the search returns something. If it doesn't, catch exception and output array of suggested shows
try {
    echo $search->performSearch();
} catch (Exception $e) {
    echo '<div class="error">Nothing returned from that search! Maybe you could check out one of these awesome shows:</div>';
    // Array of shows
    $goodShows = array("30 Rock", "It's Always Sunny In Philadelphia", "Parks and Recreation", "The Inexplicable Universe With Neil deGrasse Tyson");
    $suggestion = new NetflixSearch();
    // Iterate through array and run search each time
    foreach ($goodShows as $show) {
        $suggestion->setTitle($show);
Exemplo n.º 2
0
<div class="container">
    <div class="col-md-4 col-md-offset-4">

<img src="http://static6.businessinsider.com/image/539aedc269beddc243d29c52-800-371/netflix_web_logo.png" height="100">

<hr>


        <form action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method='POST'>
            <input type="text" name="title" placeholder="title" onclick=""><br><br>
            <input type="text" name="year" placeholder="year" onclick=""><br><br>
            <input type="text" name="director" placeholder="director" onclick=""><br><br>
            <input type="text" name="actor" placeholder="actor" onclick=""><br><br>
            <input type="submit" name="search"><br><br>
        </form>

    </div>
</div>

<?php 
if (isset($_POST['search'])) {
    $try = new NetflixSearch();
    $try->setTitle($_POST['title']);
    $try->setYear($_POST['year']);
    $try->setDirector($_POST['director']);
    $try->setActor($_POST['actor']);
    $try->search();
}
Exemplo n.º 3
0
<?php

include_once 'vendor/autoload.php';
include_once 'NetflixSearch.php';
try {
    if (isset($_POST['submit'])) {
    }
    $query = new NetflixSearch();
    $query->setDirector('Quentin Tarantino');
    $query->setTitle('Kill Bill: Vol. 2');
    echo '<pre>';
    $body = $query->searchNetflix();
    print_r($body);
} catch (Exception $e) {
    echo $e->getMessage();
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Netflix Search</title>
</head>
<body>

<form action="<?php 
echo $_SERVER['PHP_SELF'];
?>
" method="get">

    <label>Title: <input type="text" name="title"/></label><br/>