I'm currently going through a book on PHP and he hasn't yet gone through SQL Injection but I do know a little bit about it and I know that he does cover it later on in the book. But thanks for your concern!
Here is a bigger chunk of my code, including the lines you asked for:
if (isset($_GET['sort'])) {
$sort = $_GET['sort'];
} else {
$sort = 'review_date';
}
$
//retrieve reviews for this movie
$query = 'SELECT review_movie_id, review_date, reviewer_name, review_comment,
review_rating
FROM reviews
WHERE review_movie_id = ' . $_GET['movie_id'] . '
ORDER BY ' . $sort . ' ASC';
$result = mysql_query($query, $db) or die(mysql_error($db));
$mid = $result['review_movie_id'];
//display the reviews
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;"><a href=movie_details.php?movie_id=$mid&sort=review_date">Date</a></th>
<th style="width: 10em;"><a href=movie_details.php?movie_id=$mid&sort=reviewer_name">Reviewer</a></th>
<th><a href=movie_details.php?movie_id=$mid&sort=review_comment">Comments</a></th>
<th style="width: 5em;"><a href=movie_details.php?movie_id=$mid&sort=review_rating">Rating</a></th>
</tr>
ENDHTML;
while ($row = mysql_fetch_assoc($result)) {
$date = $row['review_date'];
$name = $row['reviewer_name'];
$comment = $row['review_comment'];
$rating = generate_ratings($row['review_rating']);
echo <<<ENDHTML
<tr>
<td style="verticle-align: top; text-align: center;">$date</td>
<td style="verticle-align: top;">$name</td>
<td style="verticle-align: top;">$comment</td>
<td style="verticle-align: top;">$rating</td>
</tr>
ENDHTML;
}
echo <<<ENDHTML
</div>
</body>
</html>
ENDHTML;
?>
Lines 177-180 are the lines that I set the variables in the where loop:
$date = $row['review_date'];
$name = $row['reviewer_name'];
$comment = $row['review_comment'];
$rating = generate_ratings($row['review_rating']);