Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

modify the following php code to output the result down below when given a movie

ID: 3922142 • Letter: M

Question

modify the following php code to output the result down below when given a movie title.

The following movies match filter value: “filter-value text”:

                Movie#1 stars Actor Name1, Actor Name2, … Actor Name N.

                Movie#2 stars Actor Name1, Actor Name2, … Actor Name N.

                so on and so forth...

<?php

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$filter = $_POST["filter"];
$sql = "SELECT film_id, title, release_year FROM film WHERE title LIKE "%$filter%";";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<div class="columns"> " . "<strong>" .
         "<div class="film_id">Film ID #</div> " .
         "<div class="title">Title</div> " .
         "<div class="release_year">Release Year</div> " . "</strong>" .
         "</div> <br><br> ";
      
    // output data of each row
    while(($row = $result->fetch_assoc()) && ($counter++ < $max)) {
        echo "<div class="columns"> " .
        "<div class="film_id">" . $row["film_id"]. "</div> " .
        "<div class="title">" . $row["title"]. "</div> " .
        "<div class="release_year">" . $row["release_year"]. "</div> " .
        "</div> " .
        "<br> ";
    }
} else {
    echo "0 results";
}

echo "</body> ";

$conn->close();

?>

Explanation / Answer

<?php

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname, $port);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$filter = $_POST["filter"];
$sql = "SELECT film_id, title, release_year FROM film WHERE title LIKE "%$filter%";";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<div class="columns"> " . "<strong>" .
         "<div class="film_id">Film ID #</div> " .
         "<div class="title">Title</div> " .
         "<div class="release_year">Release Year</div> " . "</strong>" .
         "</div> <br><br> ";
      
    // output data of each row
    while(($row = $result->fetch_assoc()) && ($counter++ < $max)) {
        echo "<div class="columns"> " .
        "<div class="film_id">" . $row["film_id"]. "</div> " .
        "<div class="title">" . $row["title"]. "</div> " .
        "<div class="release_year">" . $row["release_year"]. "</div> " .
        "</div> " .
        "<br> ";
    }
} else {
    echo "0 results";
}

echo "</body> ";

$conn->close();

?>