Jump to content
Larry Ullman's Book Forums

Shop.Php Problem - Chapter 8


Recommended Posts

Hi All,

 

Thank you very much for all your efforts and helps. I've got into a problem when I try to execute 'shop.php' page after putting error.html, and list_categories.html under view folder. I also put all those css and js files that I got from the download on your website to my server.

 

When I execute shop.php file on my server, it gave this error msg 'An error occurred in script '/home/ryandivi/public_html/shop.php' on line 32:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array'

 

shop.php file code is like this below:

The problem line is in bold

 

----------------------------------------------------------------------------------------------------------------------

<?php

 

// This file lists categories of products.

// This script is begun in Chapter 8.

 

// Require the configuration before any PHP code:

require ('./includes/config.inc.php');

 

// Validate the product type...

if (isset($_GET['type']) && ($_GET['type'] == 'goodies')) {

$page_title = 'Our Goodies, by Category';

$sp_type = 'other';

$type = 'goodies';

} else { // Default is coffee!

$page_title = 'Our Coffee Products';

$type = $sp_type = 'coffee';

}

 

// Include the header file:

include ('./includes/header.html');

 

// Require the database connection:

require (MYSQL);

 

// Call the stored procedure:

$r = mysqli_query($dbc, "CALL select_categories('$sp_type')");

 

// For debugging purposes:

//if (!$r) echo mysqli_error($dbc);

 

// If records were returned, include the view file:

if (mysqli_num_rows($r) > 0) {

include ('./views/list_categories.html');

} else { // Include the error page:

include ('./views/error.html');

}

 

// Include the footer file:

include ('./includes/footer.html');

?>

 

-------------------------------------------------------------------------------------------------------------

 

I followed the book exactly and don't know why I am having this trouble.. It would be really appreciated if you can tell me what the problem is..

 

Thanks

Link to comment
Share on other sites

I think you've missed the point of Larry's post the stored procedure isn't working (probably due to some kind of syntax error) to find out why (like Larry suggests) uncomment the debugging line and the script will tell you why it doesn't work.

Link to comment
Share on other sites

I uncomment the debugging line. But it still tells me the same thing. The error msg is like this:

 

"An error occurred in script '/home/ryandivi/public_html/shop.php' on line 30:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array"

 

Please see below my shop.php code. ( I think uncommenting a line isn't affecting the web page as it's just a comment. As you can see my previous post above, the debugging wasn't activating as I put double slashes in front of the code.)

-----------------------------------------------------------------------------------------------------------------------------

 

<?php

 

// This file lists categories of products.

// This script is begun in Chapter 8.

 

// Require the configuration before any PHP code:

require ('./includes/config.inc.php');

 

// Validate the product type...

if (isset($_GET['type']) && ($_GET['type'] == 'goodies')) {

$page_title = 'Our Goodies, by Category';

$sp_type = 'other';

$type = 'goodies';

} else { // Default is coffee!

$page_title = 'Our Coffee Products';

$type = $sp_type = 'coffee';

}

 

// Include the header file:

include ('./includes/header.html');

 

// Require the database connection:

require (MYSQL);

 

// Call the stored procedure:

$r = mysqli_query($dbc, "CALL select_categories('$sp_type')");

 

 

 

// If records were returned, include the view file:

if (mysqli_num_rows($r) > 0) {

include ('./views/list_categories.html');

} else { // Include the error page:

include ('./views/error.html');

}

 

// Include the footer file:

include ('./includes/footer.html');

?>

Link to comment
Share on other sites

Ryan,

 

First, I'm going to say again, per the forum rules, you need to start including your basic information (such as PHP and MySQL version) if you want help. Second, to be more explicit, take this line in the original code:

//if (!$r) echo mysqli_error($dbc);

and turn it into:

if (!$r) echo mysqli_error($dbc);

That way you'll see the error immediately after executing the stored procedure (if the stored procedure failed). What you did was just remove that line, which isn't helpful at all.

Link to comment
Share on other sites

Larry,

 

Thanks for your comments. I think my php version is 5 and mysql version is 5.0.91. I uncomment the line and see what is the issue.

 

The error msg I got is "execute command denied to user 'ryandivi_012'@'localhost' for routine 'ryandivi_ecommerce2.select_categories' An error occurred in script '/home/ryandivi/public_html/shop.php' on line 33: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given Array"

 

It looks like connection problem.. Is it?

 

You can see it here: http://ryan.divinehosting.ca/shop.php

Link to comment
Share on other sites

Okay, not to belabor the point, but you need to know, for certain, the full and exact versions of PHP and MySQL in use. Without a doubt, this is the most important thing one should know before using PHP and MySQL. Fortunately, it's easy enough to find this data out.

 

As for that error, it's not a connection problem. The user you're connecting to MySQL as does not have EXECUTE privileges.

Link to comment
Share on other sites

Depending upon many factors, you may or may not be able to test credit card transactions using your own computer. But if you're trying to develop on that level, you may want to change hosting. Or not use stored procedures.

 

I hear good things about DreamHost.

Link to comment
Share on other sites

 Share

×
×
  • Create New...