Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 5th, 2010, 05:10 PM
Authorized User
 
Join Date: Jan 2010
Posts: 13
Thanks: 2
Thanked 1 Time in 1 Post
Default Chapter 4:Displaying the reviews p.126-128

I have done this a couple of times and am just not seeing the error.....before I did all the additions the script worked perfectly and I got the success statement after creating the review table.....can anyone offer any assistance? Thanks in advance.
These are the 2 errors I get

Notice: Undefined index: movie_id in C:\wamp\www\htdocs\movie_details_new.php on line 101

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7

Here is all the code:
Code:
<?php

//function to generate ratings
function generate_ratings($rating) {
     $movie_rating = ' ';
     for ($i = 0; $i < $rating; $i++) {
         $movie_rating .= '<img src="star.png" alt="star"/>';
     }
     return $movie_rating;
 }


//take in director id and return full name
function get_director($director_id) {

    global $db;

    $query = 'SELECT
           people_fullname
        FROM
           people
        WHERE
           people_id = ' . $director_id;
    $result = mysql_query($query, $db) or die(mysql_error($db));

    $row = mysql_fetch_assoc($result);
     extract($row);

    return $people_fullname;
}

//take in the id of a lead actor and return full name
function get_leadactor($leadactor_id) {

    global $db;

    $query = 'SELECT
           people_fullname
        FROM
           people
        WHERE
           people_id = ' . $leadactor_id;
    $result = mysql_query($query, $db) or die(mysql_error($db));

    $row = mysql_fetch_assoc($result);
     extract($row);

    return $people_fullname;
}

//take in the id of a movie type and return movie name
function get_movietype($type_id) {

    global $db;

    $query = 'SELECT
           movietype_label
        FROM
           movietype
        WHERE
           movietype_id = ' . $type_id;
    $result = mysql_query($query, $db) or die(mysql_error($db));

    $row = mysql_fetch_assoc($result);
     extract($row);

    return $movietype_label;
}

//function to calculate profit,loss or break even 
function calculate_differences($takings, $cost) {

     $difference = $takings - $cost;

     if ($difference < 0) {
         $color = 'red';
         $difference = '$' . abs($difference) . ' million';
  }  elseif ($difference > 0) {
         $color = 'green';
         $difference = '$' . $difference . ' million';
  }  else {
         $color = 'blue';
         $difference = 'broke even';
}
 
   return '<span style="color:' . $color . ';">' . $difference . '</span>';
}

//connect to mysql
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));

//retrieve information
$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 = mysql_query($query, $db) or die(mysql_error($db));

$row = mysql_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_differences($row['movie_takings'],
                          $row['movie_cost']);

//display the info
echo <<<ENDHTML
<html>
 <head>
  <title>Details and Reviews for: $movie_name</title>
 </head>
 <body>
  <div style="text-align: center;">
   <h2>$movie_name</h2>
   <h3><em>Details</em></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>
    </table>
ENDHTML;

//retrieve reviews for this movie
$query = 'SELECT
       review_movie_id, review_date, reviewer_name, review_comment, movie_rating
     FROM
       reviews
     WHERE
       review_movie_id = ' . $_GET['movie_id'] . '
     ORDER BY
       review_date DESC';

$result = mysql_query($query, $db) or die(mysql_error($db));

//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;">Date</th>
      <th style="width: 10em;">Reviewer</th>
      <th>Comments</th>
      <th style="width: 5em;">Rating</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="vertical-align:top; text-align: center;">$date</td>
     <td style="vertical-align:top;">$name</td>
     <td style="vertical-align:top;">$comment</td>
     <td style="vertical-align:top;">$rating</td>
    </tr>
ENDHTML;
}
echo <<<ENDHTML
    </div>
   </body>
  </html>
ENDHTML;
?>
 
Old February 5th, 2010, 06:53 PM
Authorized User
 
Join Date: Jan 2010
Posts: 13
Thanks: 2
Thanked 1 Time in 1 Post
Default additional info

I changed the file name back to movie_details and ran table 3 and got this error on the page just above the review table

Fatal error: Function name must be a string in C:\wamp\www\htdocs\movie_details.php on line 179

I'm sure it is something little and easy but I'm not finding the error. I have tried to look back thru the other tables and make sure all the spelling is correct also but haven't found anything yet. Maybe I need a good php editor to find all the little errors for me!!!! Thanks for the assistance.
 
Old February 6th, 2010, 10:53 AM
Authorized User
 
Join Date: Jan 2010
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
Default

Note, I'm just a student too but:

I think the error is in your table3.php file. The message indicates that the $_GET array doesn't hold what it should, so the link isn't passing the parameters correctly.

Mine isn't exactly like the book, cause I like to tinker around with things, but check the line in the while loop in table3.php that does something like this:
Code:
<td><a href="movie_details.php?movie_id=$movie_id" 
	title="Click here to find out more about $row[movie_name]">$row[movie_name]</a>
</td>
You should be able to hover your mouse over the link to see what the actual URI your code is producing is as well.

Tip:
I frequently put the following two lines at the end of a program before I start typing it in.
Code:
  
echo "<pre>"; echo '$_POST '; echo print_r($_POST); echo "</pre>";
echo "<pre>"; echo '$_GET '; echo print_r($_GET); echo "</pre>";
It helps me monitor just what parameters the program is getting. This will be really useful in the next couple of chapters.

If you want, post the code for table3.php and I'll take a look. But your code looks fine for movie_details.php.
 
Old February 6th, 2010, 01:12 PM
Authorized User
 
Join Date: Jan 2010
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
Default

Just saw a problem with your code:

Code:
    $date = $row('review_date');
    $name = $row('reviewer_name');
    $comment = $row('review_comment');
    $rating = generate_ratings($row('review_rating'));
$row is an array, so you need to access it's elements with square brackets instead of parentheses:
Code:
    $date = $row['review_date'];
    $name = $row['reviewer_name'];
    $comment = $row['review_comment'];
    $rating = generate_ratings($row['review_rating']);
 
Old February 8th, 2010, 02:07 PM
Authorized User
 
Join Date: Jan 2010
Posts: 13
Thanks: 2
Thanked 1 Time in 1 Post
Default Thanks

Thanks for the advice and help.....went back and changed the () to [] and then to table 3 to check and discovered I spelled name as mane......program didn't know what to GET !!! Going to use your idea of the end statements, I think tha will help some. Thanks again
The Following User Says Thank You to drgnhiker For This Useful Post:
BozHogan (February 9th, 2010)
 
Old February 9th, 2010, 08:03 PM
Authorized User
 
Join Date: Jan 2010
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
Default

No problem. I've halfway thru chapter 7 myself, so it's a good refresher to go back and look at some of the previous stuff. Amazing how fast you forget. Keep posting if you run into trouble, it does me good too, and maybe we can beef up the participation in this forum with the activity.

Regards,
Boz
 
Old November 6th, 2010, 04:04 AM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy movie_details.php error

me too have same problem nothihg worked from above posts..
in page 121-123. when I try to browse it says: Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\movie_details.php on line 79..
Who has got the solution for it? PLz Help
binayak bhattarai
Code:
<?php
function get_director($direcror_id) {
    global $db;
    $query = 'SELECT
            people_fullname
      FROM
         people
      WHERE
         people_id = ' . $director_id;
    $result = mysql_query($query, $db) or die(mysql_error($db));
    
    $row = mysql_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 = mysql_query($query, $db) or die(mysql_error($db));

    $row = mysql_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 = mysql_query($query, $db) or die(mysql_error($db));

    $row = mysql_fetch_assoc($result);
    extract($row);
    
    return $movietype_label;
}

function calculate_differences($takings, $cost) {
    $difference = $takings - $cost;
    
    if (difference < 0) {
       $color = 'red';
       $difference = '$' . abs($difference) . ' million';
    } elseif ($difference > 0) {
       $color = 'green';
       $difference = '$' . $difference . 'million';
    } else {
       $color = 'blue';
       $difference = 'broke even';
    }

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

$db = mysql_connect('localhost', 'root', '') or
    die ('unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));


$query = 'SELECT
        movie_name, movie_year, movie_director, movie_leadactor,
        movie_tye, movie_running_time, movie_cost, movie_takings
    FROM
        movie
    WHERE
        movie_id = ' . $_GET('movie_id)';
$result = mysql_query($query, db or die(mysql_error($db));

$row = mysql_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_differences($row['movie_takings'], $row['movie_cost']);


//display the information


echo <<<ENDHTML
<html>
 <head>
  <title>Details and Reviews for: $movie_name</title>
 </head>
 <body>
  <div style="text-align: center;">
   <h2>$movie_name</h2>
   <h3><em>Details</em></h3>
   <table cellpadding="2" cellspacing="2" style="width: 70%; margin-left: auto; margin-right: auto;">
    <tr>
     <td><strong>Title</strong></strong></td>
     <td>$movie_name</td>
     <td><strong>Release Year</strong></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>
   </table></div>
 </body>
</html>
ENDHTML;

?>

Last edited by Binayak; November 6th, 2010 at 04:06 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapt. 04 Pages 124-126 Errata Andrew M. BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 December 30th, 2009 02:53 AM
problems with the reviews table in chapter 4 derrida BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 15th, 2007 03:58 AM
I've read some bad reviews; what do readers think? disruptivehair BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 11 January 18th, 2006 04:44 PM
Page 126-129 herjeulucy BOOK: Beginning ASP.NET 1.0 0 April 13th, 2005 09:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.