p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 (http://p2p.wrox.com/forumdisplay.php?f=160)
-   -   Query was empty!!!!!!!!!!!!!!!!!!!!!!!!! (http://p2p.wrox.com/showthread.php?t=55903)

gargamel March 27th, 2007 08:38 AM

Query was empty!!!!!!!!!!!!!!!!!!!!!!!!!
 
Ok, I spent hours looking for this error (query was empthy) and was not able to find anything wrong wiht my code! very frustrating!

I am using the "beginning PHP5, Apache, MySQL Web Development" book
the code is found on page 117

I would apprecitate if anyone can suggest ANYTHING.
My code is exactly the same as in book. Please take a look


<?php
//connect to the database
$link = mysql_connect("localhost", "root", "12345")
    or die(mysl_error());

//make sure we are using the right database
mysql_select_db("moviesite")
    or die(mysql_error());


$query = "SELECT movie_name, movie_director, movie_leadactor " .
     "FROM movie";

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



$movie_header=<<<EOD
<h2><center>Movie Review Database</center></h2>
<table width="70%" border="1" cellpadding="2"
    cellspacing="2" align="center">
<tr>
    <th>Movie Title</th>
    <th>Movie Director</th>
    <th>Movie Lead Actor</th>
</tr>

EOD;

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

$guery_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;
}


while($row = mysql_fetch_array($result)) {
    $movie_name = $row['movie_name'];
    $movie_director = $row['movie_director'];
    $movie_leadactor = $row['movie_leadactor'];

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

//get actor's name from the people table
get_leadactor();


    $movie_details .=<<<EOD
    <tr>
     <td>$movie_name</td>
     <td>$director</td>
     <td>$leadactor</td>
    </tr>
EOD;
}

$movie_details .=<<<EOD
<tr>
<td>Total :$num_movies Movies </td>
</tr>
EOD;

$movie_footer ="</table>";

$movie =<<<MOVIE
    $movie_header
    $movie_details
    $movie_footer
MOVIE;

echo "There are $num_movies movies in our database";
echo $movie;
?>



There it is. Either I am VERY WRONG or the book has a typo. :(

Hope you can help out

gargamel March 27th, 2007 08:58 AM

Also, I checked my data, everything looks ok, createmovie.php creates the table fine and moviedata.php populates the fields in the data as well.

Previous "table 2.php" (figure 4-3) on page 117 works fine as well.
As soon as I add those two functions function get_director() and function get_leadactor() I start encountering the issues....

:(


gargamel March 27th, 2007 10:22 AM

OK NEVER MIND!

I retyped the code again, and NO ERRORS!!

It worked. Strange! I went through the code and was not able to find anything different from the previous code (code above)

so i'll get you a launch if you can figure this one :)

cheers,
gargamel


TheDudeTux March 27th, 2007 10:57 AM

Quote:

quote:Originally posted by gargamel
 OK NEVER MIND!

I retyped the code again, and NO ERRORS!!

It worked. Strange! I went through the code and was not able to find anything different from the previous code (code above)

so i'll get you a launch if you can figure this one :)

cheers,
gargamel


Hey gargame1 Whats up!! haha Actually you beat me to it. I was debugging your code but you replied before I got back.. Anyways you had 2 errors in your code... I will show you them...

<?php
//connect to the database
$link = mysql_connect("localhost", "root", "12345")
    or die(mysl_error());


You had a typo it should be or die(mysql_error()); you forgot the "q"


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


This is your second error, Your variable is $guery_d instead of
$query_d...

$guery_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;

Sorry I was a bit late... But I hope this help finds your errors. Take care and don't worry about it... Keep Coding.
-TheDudeTux


gargamel March 27th, 2007 11:26 AM

wow! how could I miss that 20 times!

You are good :)!!

Thank you for your feedback and your fast reply. I am sure I will run into more serious problems down the road.

cheers,

gargamel


TheDudeTux March 27th, 2007 11:32 AM

Quote:

quote:Originally posted by gargamel
 wow! how could I miss that 20 times!

You are good :)!!

Thank you for your feedback and your fast reply. I am sure I will run into more serious problems down the road.

cheers,

gargamel


No worries, haha I make mistakes too when I code from time to time, sometimes you are thinking of a lot of things. But I hate debugging so I try to pay as much attention as possible to detail, but from time to time I still mess up. Keep Programming... don't let little things hold you down.
-Peace :D haha



All times are GMT -4. The time now is 04:18 PM.

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