 |
| Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Beginning PHP 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
|
|
|
|

July 14th, 2012, 05:04 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 4, p118: Warning on extract($row_e);
Hello, I have a problem. The browser returns:
"Warning: extract() expects parameter 1 to be array, null given in /customers/0/9/a/erinaceus.eu/httpd.www/php/filmsite/table3.php on line 42" when I test the program on my server. I did exactly what the book said. What's wrong? Here's my coding:
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_e);
$director=$people_fullname;
}
|
|

July 15th, 2012, 07:00 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
You get the results from the query in $row_d yet extract $row_e .... see the mistake?
|
|

July 15th, 2012, 02:22 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Lenhi confused
Thank you, but no, I don't see the mistake. In PHP, I'm still flying blind, sort of, just copying the code from the book and inserting other strings here and there. This code is hauled straight out of the book, and it is not in the errata.
|
|

July 16th, 2012, 03:20 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Still no solution to extract($row...
Quote:
Originally Posted by UseLess
Greetings,
You get the results from the query in $row_d yet extract $row_e .... see the mistake?
|
Yeah, OK; now I see it! But this does not affect the problem. This is how it is:
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);
$row_d=mysql_fetch_assoc($results_d);
extract ($row_d);
$director=$people_fullname;
}
This writes the warning message on my screen that I've seen in so many places out there on the web. Someone at Phpbuilder suggested that using globals was old-fashioned and dangerous, so perhaps I am barking up the wrong tree altogether?
|
|

July 16th, 2012, 03:41 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Boolean or array or null?
After I changed _d to _e, I got "Warning: extract() expects parameter 1 to be array, boolean given in..." instead. So, it is an exaggeration to say that it changed nothing, but it solved nothing, did it?!
|
|

July 16th, 2012, 06:23 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
Well do you have a connection to the database?
If you do have a connection to the db is the connection resource held in a variable? If it is try making the variable global within the function.
And the globals the person at phpbuilder is on about are different to the globals your using within the function.
|
|

July 16th, 2012, 10:17 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
?
Well, there must be a connection, mustn't there, since the names do appear in the table. Here is the link: http://erinaceus.eu/php/filmsite/table3.php
Would you please clarify "the connection resource held in a variable" and "making the variable global within the function".
|
|

July 16th, 2012, 01:05 PM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
Nevermind about the resource as it's not needed the error is probably due to not getting a result or the director and lead actor are not set for a film.
Try this:
PHP Code:
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);
if (!$results_d) { echo "Could not successfully run query ($query_d) from DB: " . mysql_error(); exit; }
if (mysql_num_rows($results_d) == 0) { echo "No rows found, nothing to print so am exiting"; exit; }
$row_d = mysql_fetch_assoc($results_d); extract ($row_d); $director = $people_fullname; }
And lookup variable scope in google which will explain why you may need to make a variable global if you want to alter/set it's value within a function. It'll also be a lot more informative than the explanation on page 68 ;)
|
|

July 18th, 2012, 06:25 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nothing in the database?
Since I got the if(!results_d), it would seem that there is nothing in the db, which is crazy, since I get names in the columns if I don't run those queries, but when I do, the table is replaced by the ereor message after (!results...
|
|

July 19th, 2012, 09:56 AM
|
|
Friend of Wrox
|
|
Join Date: May 2011
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
|
|
Greetings,
The error message you get, if using the above code, will also include the query sent to the db from this you should be able to determine what, if any, information is not where it should be.
|
|
 |