Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 2nd, 2007, 12:40 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default movie_details.php issues

Hello members,

I seem to be having issues wit hthe code starting on page 124 and going to and including page 127 (movie_details.php)

I have typed the entire code but cant get the "Figure4-6" to display. I can't seem to find the error in my code. It would be greately appriciated if anyone could look into my problem.

I will paste the entire code followed by the error I am seeing.
THANK YOU!!


***CODE***


<?php
$link = mysql_connect("localhost","root","12345")
    or die(mysql_error());

mysql_select_db("moviesite")
    or die (mysql_error());



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

if ($difference < 0) {
    $difference = substr($difference, 1);
    $font_color = 'red';
    $profit_or_loss = "$" . $difference . "m";
} elseif ($difference > 0) {
    $font_color ='green';
    $profit_or_loss = "$" . $difference . "m";
}else {
    $font_color = 'blue';
    $profit_or_loss = "Broke even";
}
    return "" . $profit_or_loss . "";
}
?>



function get_director() {
    global $movie_director;
    global $director;

    $query_d = "SELECT people_fullname " .
        "FROM people " .
        "WHERE people_id='$movie_director'";
    $results_d = mysql_query($query_d)
        or die(mysql_error());
    $row_d = mysql_fetch_array($results_d);
    extract($row_d);
    $director = $people_fullname;
}


function get_leadactor() {
    global $movie_leadactor;
    global $leadactor;

    $query_a = "SELECT people_fullname " .
        "FROM people " .
        "WHERE people_id='$movie_leadactor'";
    $results_a = mysql_query($query_a)
        or die(mysql_error());
    $row_a = mysql_fetch_array($results_a);
    extract($row_a);
    $leadactor = $people_fullname;
}


$query = "SELECT * FROM movie " .
    "WHERE movie_id='" . $_GET['movie_id'] . "'";

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

$movie_table_headings=<<<EOD
    <tr>
        <th>Movie Title</th>
        <th>Year of Release</th>
        <th>Movie Dirctor</th>
        <th>Movie Load Actor</th>
        <th>Movie Running Time</th>
        <th>Movie Health</th>
    </tr>
    EOD;

while ($row = mysql_fetch_array($result)) {
    $movie_name = $row['movie_name'];
    $movie_director = $row['movie_director'];
    $movie_leadactor = $row['movie_leadactor'];
    $movie_year = $row['movie_year'];
    $movie_running_time = $row['movie_running_time']." mins";
    $movie_takings = $row['movie_takings'];
    $movie_cost = $row['movie_cost'];

//get director's name from people table
get_director();

//get lead actor's name from peole table
get_leadactor();

}


$movie_health = calculate_differences($movie_takings, $movie_cost);
$page_start =<<<EOD
<html>
<head>
<title> Detais and Reviews for: $movie_name</title>
</head>
<body>
EOD;

$movie_details =<<<EOD
<table width="70%" border="0" cellspacing="2"
    cellpadding="2" align="center">
<tr>
<th colspan="6">[u]<h2>$movie_name: Details</h2></u></th>
</tr>
$movie_table_headings
<tr>
    <td width="33%" align="center">$movie_name</td>
    <td align="center">$movie_year</td>
    <td align="center">$director</td>
    <td align="center">$leadactor</td>
    <td align="center">$movie_running_time</td>
    <td align="center">$movie_health</td>
</tr>
</table>
<br>
<br>
EOD;
$page_end =<<<EOD
</body>
</html>
EOD;
$detailed_movie_info =<<<EOD
    $page_start
    $movie_details
    $page_end
EOD;

echo $detailed_movie_info;
mysql_close();




*****THIS IS THE ERROR****

function get_director() { global $movie_director; global $director; $query_d = "SELECT people_fullname " . "FROM people " . "WHERE people_id='$movie_director'"; $results_d = mysql_query($query_d) or die(mysql_error()); $row_d = mysql_fetch_array($results_d); extract($row_d); $director = $people_fullname; } function get_leadactor() { global $movie_leadactor; global $leadactor; $query_a = "SELECT people_fullname " . "FROM people " . "WHERE people_id='$movie_leadactor'"; $results_a = mysql_query($query_a) or die(mysql_error()); $row_a = mysql_fetch_array($results_a); extract($row_a); $leadactor = $people_fullname; } $query = "SELECT * FROM movie " . "WHERE movie_id='" . $_GET['movie_id'] . "'"; $result = mysql_query($query, $link) or die(mysql_error()); $movie_table_headings=<< Movie Title Year of Release Movie Dirctor Movie Load Actor Movie Running Time Movie Health EOD; while ($row = mysql_fetch_array($result)) { $movie_name = $row['movie_name']; $movie_director = $row['movie_director']; $movie_leadactor = $row['movie_leadactor']; $movie_year = $row['movie_year']; $movie_running_time = $row['movie_running_time']." mins"; $movie_takings = $row['movie_takings']; $movie_cost = $row['movie_cost']; //get director's name from people table get_director(); //get lead actor's name from peole table get_leadactor(); } $movie_health = calculate_differences($movie_takings, $movie_cost); $page_start =<< EOD; $movie_details =<<
$movie_name: Details
$movie_table_headings $movie_name $movie_year $director $leadactor $movie_running_time $movie_health

EOD; $page_end =<< EOD; $detailed_movie_info =<<<EOD $page_start $movie_details $page_end EOD; echo $detailed_movie_info; mysql_close();
Reply With Quote
  #2 (permalink)  
Old April 2nd, 2007, 02:02 PM
jminatel's Avatar
Wrox Staff
Points: 17,437, Level: 57
Points: 17,437, Level: 57 Points: 17,437, Level: 57 Points: 17,437, Level: 57
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2003
Location: Indianapolis, IN, USA.
Posts: 1,933
Thanks: 57
Thanked 128 Times in 97 Posts
Default

What book?

Jim Minatel
Senior Acquisitions Editor
Wiley Technology Publishing
WROX Press
Blog: http://wroxblog.typepad.com/
Jim's Book of the week: No book this week - Donate to the Red Cross!
Reply With Quote
  #3 (permalink)  
Old April 2nd, 2007, 02:35 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry forgot that part :)

It is "Beginning PHP5, Apache, MYSQL Web Development"

Thanks :)


Reply With Quote
  #4 (permalink)  
Old April 3rd, 2007, 06:28 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by gargamel
 Sorry forgot that part :)

It is "Beginning PHP5, Apache, MYSQL Web Development"

Thanks :)


Hey Gargamel whats up? Hey, I found your errors.. I will place them below with ****** to show where they are.

<?php
$link = mysql_connect("localhost","root","12345")
    or die(mysql_error());

mysql_select_db("moviesite")
    or die (mysql_error());



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

if ($difference < 0) {
    $difference = substr($difference, 1);
    $font_color = 'red';
    $profit_or_loss = "$" . $difference . "m";
} elseif ($difference > 0) {
    $font_color ='green';
    $profit_or_loss = "$" . $difference . "m";
}else {
    $font_color = 'blue';
    $profit_or_loss = "Broke even";
}
    return "" . $profit_or_loss . "";
}
*** ?> ******** First Error *****************
    You have to remove closing syntax for php... This will enable the code below to become active.... So just delete the <?


function get_director() {
    global $movie_director;
    global $director;

    $query_d = "SELECT people_fullname " .
        "FROM people " .
        "WHERE people_id='$movie_director'";
    $results_d = mysql_query($query_d)
        or die(mysql_error());
    $row_d = mysql_fetch_array($results_d);
    extract($row_d);
    $director = $people_fullname;
}


function get_leadactor() {
    global $movie_leadactor;
    global $leadactor;

    $query_a = "SELECT people_fullname " .
        "FROM people " .
        "WHERE people_id='$movie_leadactor'";
    $results_a = mysql_query($query_a)
        or die(mysql_error());
    $row_a = mysql_fetch_array($results_a);
    extract($row_a);
    $leadactor = $people_fullname;
}


$query = "SELECT * FROM movie " .
    "WHERE movie_id='" . $_GET['movie_id'] . "'";

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

$movie_table_headings=<<<EOD
    <tr>
        <th>Movie Title</th>
        <th>Year of Release</th>
        <th>Movie Dirctor</th>
        <th>Movie Load Actor</th>
        <th>Movie Running Time</th>
        <th>Movie Health</th>
    </tr>
********** EOD; ********** Error 2 ************
Your EOD should be all the way back to the left edge... Because of this it causes white space.

while ($row = mysql_fetch_array($result)) {
    $movie_name = $row['movie_name'];
    $movie_director = $row['movie_director'];
    $movie_leadactor = $row['movie_leadactor'];
    $movie_year = $row['movie_year'];
    $movie_running_time = $row['movie_running_time']." mins";
    $movie_takings = $row['movie_takings'];
    $movie_cost = $row['movie_cost'];

//get director's name from people table
get_director();

//get lead actor's name from peole table
get_leadactor();

}


$movie_health = calculate_differences($movie_takings, $movie_cost);
$page_start =<<<EOD
<html>
<head>
<title> Detais and Reviews for: $movie_name</title>
</head>
<body>
EOD;

$movie_details =<<<EOD
<table width="70%" border="0" cellspacing="2"
    cellpadding="2" align="center">
<tr>
<th colspan="6">[u]<h2>$movie_name: Details</h2></u></th>
</tr>
$movie_table_headings
<tr>
    <td width="33%" align="center">$movie_name</td>
    <td align="center">$movie_year</td>
    <td align="center">$director</td>
    <td align="center">$leadactor</td>
    <td align="center">$movie_running_time</td>
    <td align="center">$movie_health</td>
</tr>
</table>
<br>
<br>
EOD;
$page_end =<<<EOD
</body>
</html>
EOD;
$detailed_movie_info =<<<EOD
    $page_start
    $movie_details
    $page_end
EOD;

echo $detailed_movie_info;
mysql_close();

This should be it... Next just save the work and then http://localhost/movie_details.php You should see "Broke even" in blue text.. Don't worry their is no data yet... Simply go to http://localhost/table3.php and click the link.. Now you will see movie_details file in action.. It will show the calculations etc.

**Note at the end of the code there is no ?> after the mysql_close(); part. I don't know if that is an error or not considering it still runs with out closing the php with <? maybe the authors kept it open for the next section not sure. But you can keep it open or close and it works.. Just a thought. Hope this helps! Take care and keep coding... -TheDudeTux


Reply With Quote
  #5 (permalink)  
Old April 3rd, 2007, 07:53 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It works!!!!!! :)

Hi thedudetux, here we meet again :). But it seems so easy, why could not I find those errors hehe. Thank you once again!

I thought we could not have "white space" after "EOD" but not before. That is something new for me.
.....I'm almost on chapter 5 yey.

Thank you once again. I have strange feeling that I will be back :).

Your help is GREATLY appriciated..!!!

Gargamel

Reply With Quote
  #6 (permalink)  
Old April 3rd, 2007, 08:34 AM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by gargamel
 It works!!!!!! :)

Hi thedudetux, here we meet again :). But it seems so easy, why could not I find those errors hehe. Thank you once again!

I thought we could not have "white space" after "EOD" but not before. That is something new for me.
.....I'm almost on chapter 5 yey.

Thank you once again. I have strange feeling that I will be back :).

Your help is GREATLY appriciated..!!!

Gargamel


Oh no problem Gargamel happy to help! Yeah sometimes trial and error will help you learn even though its a pain.. The books is kind of funky too. Sometimes its difficult to understand what they are thinking or when they are trying to explain things. But I must admit the book has a lot of cool things in it. It's just trying to understand some of it that can be hard at times... Well, I got to get going the sun is starting to come up in the U.S. Are you from the UK? Take Care

Reply With Quote
  #7 (permalink)  
Old April 3rd, 2007, 09:32 AM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes I agree, at some times newbies can find it difficult - As in the last example/problem I had, nowhere was it indicated that ?> needs to be removed from the code. I guess author expects you to know that by then.

Overall I think the book is excellent for starters. I certainly did learn a lot, and I am only finishing chapter 4.

I am from Toronoto Canada.... :).
You finished the book? :)


Reply With Quote
  #8 (permalink)  
Old April 3rd, 2007, 04:53 PM
Authorized User
 
Join Date: Feb 2006
Location: , , .
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by gargamel
 Yes I agree, at some times newbies can find it difficult - As in the last example/problem I had, nowhere was it indicated that ?> needs to be removed from the code. I guess author expects you to know that by then.

Overall I think the book is excellent for starters. I certainly did learn a lot, and I am only finishing chapter 4.

I am from Toronoto Canada.... :).
You finished the book? :)


haha no... I haven't finished the book, almost though. I'm reading other books along with it when I get a chance... But hopefully I will get done sometime soon. :-) Take care

Reply With Quote
  #9 (permalink)  
Old October 18th, 2010, 03:31 PM
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem with getting the information about the movie

Hi Guys,
I'm also having a problem on this example. When i click on the hyperlink, i only see the page with no information about that movie. I only see the broke even in blue underneath the movie healths with the other headings but nothing else. Can anybody help me on this? That would b really appreciated.
Reply With Quote
  #10 (permalink)  
Old October 21st, 2010, 09:49 AM
Registered User
 
Join Date: Oct 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sup Guyz,

how much of this code are we allowed to alter?
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 - PHP installation issues Abelmiah BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 June 21st, 2009 05:01 PM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Chapter 4 P124 - movie_details Pheeal Beginning PHP 0 January 27th, 2006 09:16 AM
need help with movie_details.php code kjames1973 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 December 26th, 2004 03:28 PM
PHP installation issues, yet again donh BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 September 22nd, 2003 07:12 PM



All times are GMT -4. The time now is 02:56 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.