Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 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 Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2012, 05:04 PM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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;
}
Reply With Quote
  #2 (permalink)  
Old July 15th, 2012, 07:00 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

You get the results from the query in $row_d yet extract $row_e .... see the mistake?
Reply With Quote
  #3 (permalink)  
Old July 15th, 2012, 02:22 PM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #4 (permalink)  
Old July 16th, 2012, 03:20 AM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Still no solution to extract($row...

Quote:
Originally Posted by UseLess View Post
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?
Reply With Quote
  #5 (permalink)  
Old July 16th, 2012, 03:41 AM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?!
Reply With Quote
  #6 (permalink)  
Old July 16th, 2012, 06:23 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

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.
Reply With Quote
  #7 (permalink)  
Old July 16th, 2012, 10:17 AM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default ?

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".
Reply With Quote
  #8 (permalink)  
Old July 16th, 2012, 01:05 PM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

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 ;)
Reply With Quote
  #9 (permalink)  
Old July 18th, 2012, 06:25 PM
Registered User
Points: 33, Level: 1
Points: 33, Level: 1 Points: 33, Level: 1 Points: 33, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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...
Reply With Quote
  #10 (permalink)  
Old July 19th, 2012, 09:56 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 10 - parseXML warning scottgardner BOOK: Professional iPhone and iPad Database Application Programming 0 May 1st, 2011 12:47 PM
Chapter 10 orderrecord extract.csv file prudviarrobotha BOOK: Expert SQL Server 2005 Integration Services ISBN: 978-0-470-13411-5 0 July 20th, 2009 09:53 PM
Chapter 9 JavaScript Warning Message Page 304 workib BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 May 28th, 2008 04:42 PM
Chapter 5 -- Sample 1: Zip Code Extract mt BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 1 February 20th, 2006 04:41 PM
chapter 15 cart.php Warning: mysql_fetch_array(): pink BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 19th, 2005 07:49 PM



All times are GMT -4. The time now is 09:54 AM.


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