0

I am currently working through a PHP textbook to create a movie review website, however, the format of the page I have created is incorrect and I can't see the difference between my code and the code in the textbook. Here is a screenshot of the page I have created: http://imgur.com/a/EBNxk

"Date" is supposed to be a table header alongside "Reviewer", "Comments" and "Rating". The "Reviews" header is also meant to be below the movie details and above "Date", "Reviewer", "Comment", and "Rating". The full code of the page is included below, I know the problem is probably going to be between the html tags but I'll include it all just incase.

EDIT: I see now that I left a quote mark out on line 130. Fixing this puts "Date" along with the other headers as it should be. But the Reviews header is still above the movie details.

<?php
function get_director($director_id)
{
    global $db;
    $query = "SELECT people_fullname FROM people WHERE people_id = ". $director_id;
    $result = mysqli_query($db,$query) or die(mysqli_error($db));
    $row = mysqli_fetch_assoc($result);
    extract($row);
    return $people_fullname;
}

function get_leadactor($leadactor_id)
{
    global $db;
    $query = "SELECT people_fullname FROM people WHERE people_id = ". $leadactor_id;
    $result = mysqli_query($db,$query) or die(mysqli_error($db));
    $row = mysqli_fetch_assoc($result);
    extract($row);
    return $people_fullname;
}

function get_movietype($type_id)
{
    global $db;
    $query = "SELECT movietype_label FROM movietype WHERE movietype_id = ". $type_id;
    $result = mysqli_query($db,$query) or die(mysqli_error($db));
    $row = mysqli_fetch_assoc($result);
    extract($row);
    return $movietype_label;
}

function generate_stars($rating)
{
    $stars = " ";
    for($i = 0; $i <= $rating; $i++)
    {
        $stars.= '<img src = "star.png" alt = "star " />';
    }
    return $stars;
}

function calculate_difference($takings,$cost)
{
    $difference = $takings - $cost;

    if($difference<0)
    {
        $color = "red";
        $difference = "$ ".abs($difference)." million";
    }
    else if ($difference > 0)
    {
        $color = "green";
        $difference = "$ ".abs($difference)." million";
    }
    else
    {
        $color = "blue";
        $difference = "$ ".abs($difference)." million";
    }

    return "<span style = \"color:".$color.";\">".$difference."</span>";
}

$db = mysqli_connect('localhost','root') or die('Unable to connect');
mysqli_select_db($db,'moviesite') or die (mysqli_error($db));

$query = "SELECT movie_name, movie_year, movie_director, movie_leadactor,
          movie_type, movie_running_time, movie_cost, movie_takings
          FROM movie
          WHERE movie_id = ".$_GET["movie_id"];
$result = mysqli_query($db,$query);
$row = mysqli_fetch_assoc($result);

$movie_name = $row['movie_name'];
$movie_director = get_director($row['movie_director']);
$movie_leadactor = get_leadactor($row['movie_leadactor']);
$movie_year = $row['movie_year'];
$movie_running_time = $row['movie_running_time']." mins";
$movie_takings = $row['movie_takings']." million";
$movie_cost = $row['movie_cost']." million";
$movie_health = calculate_difference($row['movie_takings'],$row['movie_cost']);

echo <<<ENDHTML
<html>
    <head>
    <title> Details for $movie_name </title>
    </head>

    <body>
    <div style = "text-align:center">
    <h2> $movie_name </h2>
    <h3> Details </h3>
    <table cellpadding = "2" cellspacing = "2" style = "width:70%; margin-left:auto; margin-right:auto">
        <tr>
            <td> <strong> Title </strong></td>
            <td> $movie_name </td>
            <td> <strong> Release Year </strong></td>
            <td> $movie_year </td>
        </tr>
        <tr>
            <td> <strong> Movie Director </strong></td>
            <td> $movie_director </td>
            <td> <strong> Cost </strong></td>
            <td> $movie_cost </td>
        </tr>
         <tr>
            <td> <strong> Lead Actor </strong></td>
            <td> $movie_leadactor </td>
            <td> <strong> Takings </strong></td>
            <td> $movie_takings </td>
        </tr>
        <tr>
            <td> <strong> Running Time </strong></td>
            <td> $movie_running_time </td>
            <td> <strong> Health </strong></td>
            <td> $movie_health </td>
        </tr>
ENDHTML;

$query = 'SELECT review_movie_id, review_date, reviewer_name, review_comment, review_rating
            FROM reviews
            WHERE review_movie_id = '.$_GET['movie_id'] . '
            ORDER BY review_date DESC';
$result = mysqli_query($db, $query) or die(mysqli_error($db));

echo <<<ENDHTML
<h3><em>Reviews</em></h3>
<table cellpadding = "2" cellspacing = "2"
    style = "width:90%; margin-left:auto; margin-right:auto;>
    <tr>
        <th style = "width: 7em"> Date </th>
        <th style = "width: 10em"> Reviewer </th>
        <th> Comments </th>
        <th style = "width: 5em"> Rating </th>
    </tr>
</table>
ENDHTML;

while($row = mysqli_fetch_assoc($result))
{
    $date = $row['review_date'];
    $name = $row['reviewer_name'];
    $comment = $row['review_comment'];
    $rating = generate_stars($row['review_rating']);

    echo <<<ENDHTML
    <td style = "vertical-align: top; text-align:center"> $date </td>
    <td style = "vertical-align: top; text-align:center"> $name </td>
    <td style = "vertical-align: top; text-align:center"> $comment </td>
    <td style = "vertical-align: top; text-align:center"> $rating </td>
    <br/>
ENDHTML;

}

echo <<< ENDHTML

    </div>
    </body>
</html>


ENDHTML;

?>
2
  • You should have trs for each review. The stars issue I would guess is an image location issue? Check your developer console. Commented Jul 28, 2016 at 12:45
  • This also is open to SQL injections. You should use parameterized queries with the mysqli prepared statements. Commented Jul 28, 2016 at 12:47

1 Answer 1

1

Try closing the quote marks on style:

<table cellpadding = "2" cellspacing = "2" style = "width:90%; margin-left:auto; margin-right:auto;">
<tr>
    <th style = "width: 7em"> Date </th>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.