Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 June 4th, 2004, 11:54 AM
Authorized User
 
Join Date: May 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Well (1) I am correctly logged on as $link = mysql_connect("localhost","root",NULL) and the table3.php runs fine, so I think that is not the problem.

As for hard coding the SELECT statement, I noticed that review_movie_id='1' in the address line of the browser and I am expecting the result in the browser to be the same as figure 4-7 on page 132 which show the results for the movie Bruce Almighty. When I hard coded '1' in the SELECT statement I got exactly the same error as when the code that is supposed to be in there is used (so at least it's consistent. This is the browser response, hard coded or not:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Program Files\Apache Group\Apache2\test\movie_details.php on line 115

Notice: Uninitialized string offset: 0 in C:\Program Files\Apache Group\Apache2\test\movie_details.php on line 149

Notice: Uninitialized string offset: 0 in C:\Program Files\Apache Group\Apache2\test\movie_details.php on line 150

Notice: Uninitialized string offset: 0 in C:\Program Files\Apache Group\Apache2\test\movie_details.php on line 151

Notice: Uninitialized string offset: 0 in C:\Program Files\Apache Group\Apache2\test\movie_details.php on line 152

Notice: Uninitialized string offset: 0 in C:\Program Files\Apache Group\Apache2\test\movie_details.php on line 153
Bruce Almighty: Details
Movie Title Year of Release Movie Director Movie Lead Actor Movie Running Time Movie Health
Bruce Almighty 2003 Tom Shadyac Jim Carrey 102 mins $5m

Thanks again with all the help and I'm sorry this problem has not gone away yet.

Best,

JAH

 
Old June 4th, 2004, 01:29 PM
Authorized User
 
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok... have you tried echoing $review_query to see what the EXACT query is? Do that, then take that query (copy/paste) and enter it into mysql (through phpmyadmin) to see what it returns.

One of two things is happening here... either the query isn't right, and for whatever reason is not returning any rows from MySQL, or the query is correct, and somehow the connection isn't being made.

As a last resort, try removing $link from the query so it looks like this:
Code:
$review_result = mysql_query($review_query) or die(mysql_error());
 
Old June 6th, 2004, 12:02 PM
Authorized User
 
Join Date: May 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi All;

Again, thank you for your advice and help.

This stuff remains beyond me. Yes, I "echo"ed $review_query and the exact result is: SELECT * FROM reviews WHERE review_movie_id ='1' ORDER BY review_date DESC which as far as I understand is correct.

Next, I took this query and entered it in the command line monitor (after having signed on as "root" and entered the command USE wiley) and the query produced the correct 3 records that id='1' should produce. Then I went to phpMyAdmin and in the SQL menu pasted the query into text area and upon pressing the "GO" button obtained a table of correct values as follows:

Showing rows 0 - 2 (3 total, Query took 0.0018 sec)

SQL-query : [Edit] [Explain SQL] [Create PHP Code]
SELECT *
FROM reviews
WHERE review_movie_id = '1'
ORDER BY review_date DESC LIMIT 0 , 30


              row(s) starting from record #
in horizontal horizontal (rotated headers) vertical mode and repeat headers after cells
         Sort by key: review_movie_id (Ascending) review_movie_id (Descending) None
           review_movie_id review_date review_name review_reviewer_name review_comment review_rating
      1 2003-08-10 Woo hoo! Peppermint Patty Wish I'd have seen it sooner! 5
      1 2003-08-02 This movie rocks! John Doe I thought this was a great movie even though
   ... 4
      1 2003-08-01 An okay movie Billy Bob This was an okay movie. I liked Eraserhead better. 2
  With selected:


As a last resort, I removed the $link variable in the $review_result line as suggested. Once again, the exact same error page was generated in the browser.

I'm not sure how useful this exercise is. As mentioned, in Mike's message (6/3/04, 8:32:06 AM, above) "Please note that much of the code does not take error_reporting = E_ALL into account, in the interest of keeping the code as tight as possible. The book would be twice as long if we wrote it with error checking and trapping in mind." If the book's program codes may have many more error "Warnings" and "Notices" yet to be encountered, I think it would be to everyone's benefit to return error reporting to the level it was originally, which evidently IS supported by the code in the book. After all, I am a beginner at AMP and I'm just trying to get on first base. I am not rounding 3rd and heading for home and don't need to know all the niceties of SQL/php. If I can just get through this book without wasting countless hours chasing down "Warnings" and "Notices" that I don't yet understand, hopefully subsequently, I can go on to more advanced books and learn the advanced considerations.

I appreciate your help and advice and don't mean to sound unappreciative.
Best,

JAH

 
Old June 6th, 2004, 06:05 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi John,
Again turning down error_reporting is a bad thing, even if you are a beginner, it's better to learn what the errors mean and how to correct them even if that means building on the book's examples. Secondly warnings won't go away if you turn off notices. Warnings are important errors, meaning most times that something is not working, in your case the warnings say that your SQL query failed. This is very important information, without this information you'd have no idea what's going wrong in your script and you'd still have a non-working program. And again, the notices that you're seeing are a direct result of your query failing, these will be fixed when you fix the warning error.

[opinion]
I personally don't think its a good idea for Wiley to publish PHP books that don't address error_reporting = E_ALL, even if it results in a longer book, because, IMO, this is a very important thing to learn in PHP. It's a crucial piece of learning the language, just as crucial as control structures or functions or any other part of the language. I don't have the book, and I'm not knocking on the authors. From what I've seen of it, it hasn't been *that* off base.
[/opinion]

If you encounter more of these errors I'd be happy to help you understand what they mean and how to fix them.

I have an observation on this snip:

Code:
while($review_row = mysql_fetch_array($review_result))
{
     $review_flag =1;
     $review_title[] = $review_row['review_name'];
     $reviewer_name[] = ucwords($review_row['review_reviewer_name']);
     $review[] = $review_row['review_comment'];
     $review_date[] = $review_row['review_date'];
     $review_rating[] = generate_ratings($review_row['review_rating']);
}

$review_query = "SELECT
                         *
               FROM
                         reviews
               WHERE
                          review_movie_id ='".$_GET['movie_id']."'
               ORDER BY
                          review_date DESC";

$review_result = mysql_query($review_query,$link) or die(mysql_error());
You have the $review_result variable being created *after* the while loop that accesses it in this snip, the $review_query and $review_result variables should be created before the while loop.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old June 7th, 2004, 12:35 AM
Authorized User
 
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Re: error_reporting
Yes, I agree that error_reporting = E_ALL is great programming practice. I didn't mean to imply that the book didn't address handling notices. It does. In fact, in Chapter 8, Handling and Avoiding Errors, we address it directly:
Quote:
quote:Note that as of PHP 4 the default error reporting does not show E_NOTICE errors. However, you may want to show them during development. Enabling E_NOTICE errors for debugging can warn you about possible bugs and/or bad programming practices.
What I meant to say was that we didn't include error_reporting = E_ALL in the code, because PHP does not have it set by default. But it is definitely addressed in the book, in a chapter dedicated to Errors. I know you don't have a copy, as you have alluded to a few times already. Perhaps you should pick one up! ;)

 
Old June 7th, 2004, 01:24 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I thought that was probably the case with saving error_reporting for its own chapter (Yes, I shouldn't make opinions on a book I haven't seen). And like I said, from what little I've seen of it hasn't been /that/ off base anyway. The code is a little more verbose in some areas than for my personal taste, and the HTML could use a touch of modern standards, (don't take that personally, I'm always preaching standards), but everyone has their way of presenting the material. I wouldn't mind actually seeing the book but I've been pretty busy with my own book authoring and my PEAR Mail_IMAP package, I have a couple PERL books and an ASP book I'd like to read too ;). I did break down and download the source code so I'd at least know what people were referring to in their questions! I think it's great that you guys are at least on here fielding questions.

Re: error_reporting, well, that also depends on how the user installed PHP (not-with-standing following the book's installation instructions to the letter), it comes with two ini files. The 'recommended' ini file has error_reporting set to E_ALL by default, granted it also has display_errors = Off and log_errors = On, which has created havoc for beginners too.

I went through these trials and tribulations when I was learning PHP using the now outdated Beginning PHP 4 Wrox book. But I had to cope with learning how to write code with register_globals = Off too. At first I just ignored the (then) new settings, and after getting some experience under my belt I realized that wasn't the best path to take. I can also recall having error_reporting set to error_reporting = E_ALL & ~E_NOTICE (To explain that for John, that means report all errors with the exception of notices) too and I spent many hours trying to track down "strange" bugs in my code because I had mispelled a variable or something equally as stupid that would have probably been caught with E_ALL. These days I wouldn't dare try to code without it.



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old June 7th, 2004, 03:44 AM
Authorized User
 
Join Date: May 2004
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

RE: standards
Actually, Jason and I are both standards nuts, too. Actually, I'm a nut, he's a Nazi. And, he was the tech editor for the book. We just made a decision to NOT use standards because they were not quite mainstream enough yet, and of course, you don't want to detract from the content of the book, i.e. PHP, MySQL, and Apache. Otherwise, you'd be fielding a lot of CSS questions in here!

Believe me, almost every <table> tag left a bad taste in my mouth :)

As for the verbosity, I have to agree with you. My code is usually much tighter. But, again, when writing for a specific audience, one tries to make concessions. That's not to say we always get it exactly right, but we certainly try to cater to the intended audience.

I'm happy to field questions, but I'm certainly glad to have you in here fielding them as well. Ever get over to PHPBuilder.com? Lots of great people there as well, and your expertise would be quite welcome. Just make sure you bring a quirky sense of humor, too -- those guys truly are nutcases :)

 
Old June 7th, 2004, 02:36 PM
Authorized User
 
Join Date: Jun 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

John,

Have you found a solution to the problem yet? Just curious.

--Jason

 
Old June 7th, 2004, 03:04 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

lol, yes, Elizabeth invited me over to PHPBuilder. I do check in over there once in a while. :)

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old June 7th, 2004, 05:22 PM
Authorized User
 
Join Date: May 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DEBUGGED - - - at last..............

The code as downloaded contains errors. First I had the "Undefined Variable" Notice. To get rid of those notices I had to declare $movie_rating = "" just after the function generate_ratings($review_rating) on line 55. Then I had to declare $review_flag = "" just after the while($row = mysql_fetch_array($movie_result)) section. Finally, I had to add $review_details = "" just before the while($i<sizeof($review)) statement. I still have not read a description of when or if one needs to declare a variable or can just go ahead and use it.

The real break came with the post from Rich (a deep bow and many thanks) who pointed out that the $review_query = "SELECT... code and the $review_result... code should occur before the while($review_row = mysql_fetch_array($review_result))... code. This is not the way the code, as downloaded, is and upon changing the order, it all worked fine.

Well, actually, there were a few other minor problems. Inside the function generate_ratings($review_rating) reference is made to an image file called 'thumbsup.gif' which is evidently supposed to be in the same directory as the program. I could not find that it was ever provided, so I made up one of my own and needed to compensate by changing the width of the review cell to 40% and the review_rating cell to 20% (but that's minor stuff).

It now runs and looks like the figure 4-7 in the book.

Phew, what a job and too bad it takes away so much time from getting on with the chapters in the book.

Finally, I did switch the error reporting. I had hoped if I just switched the error reporting to E_ERROR that I would get rid of the warnings and notices and the script would finish its work. Well I did get rid of the warnings, but now the script just halted with no explanation at all. Drat! I went back to E_ALL. At least some hints are better than nothing. So I concur, and now agree with the notion to use E_ALL.

Thanks to all for your patience and your helpful ideas. Without this forum, I'm sure I would not be able to finish this book.
Best,

JAH






Similar Threads
Thread Thread Starter Forum Replies Last Post
undefined variable zenixcomp BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 October 31st, 2008 06:11 AM
How to know a variable is undefined? Edward King Javascript How-To 3 June 14th, 2005 10:14 AM
Chapter 7 check_image.php, undefined variable Ron_Bingham BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 3rd, 2005 10:31 PM
Undefined variable majidnakit Beginning PHP 2 April 16th, 2005 11:23 PM
undefined variable !! cody44 Beginning PHP 3 January 20th, 2005 05:47 PM





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