Jump to content
Larry Ullman's Book Forums
Sign in to follow this  

Recommended Posts

Hi All, 

 

I'm a newbie in PHP/MySQL and this place has been helpful, Larry thanks. My coffee site is not coming up while knowledge is power is up and firing. I was very happy until my coffee site refuses to come up. This is the error message I'm getting:

 

An error occurred in script 'C:\xampp\htdocs\ecom\html\views\home.html' on line 14:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Array

(

[0] => Array

(

[function] => my_error_handler

[args] => Array

(

[0] => 2

[1] => mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

[2] => C:\xampp\htdocs\ecom\html\views\home.html

[3] => 14

[4] => Array

(

[GLOBALS] => Array

*RECURSION*

[_POST] => Array

(

)



[_GET] => Array

(

)



[_COOKIE] => Array

(

[phpSESSID] => 30nvl7ovcsvt9lgskus5jacdq6

)



[_FILES] => Array

(

)



[live] =>

[contact_email] => you@example.com

[page_title] => Coffee - Wouldn't You Love a Cup Right Now?

[dbc] => mysqli Object

(

[affected_rows] => -1

[client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

[client_version] => 50008

[connect_errno] => 0

[connect_error] =>

[errno] => 1305

[error] => PROCEDURE ecommerce1.select_sale_items does not exist

[field_count] => 0

[host_info] => localhost via TCP/IP

[info] =>

[insert_id] => 0

[server_info] => 5.5.16

[server_version] => 50516

[sqlstate] => 42000

[protocol_version] => 10

[thread_id] => 406

[warning_count] => 0

)



[r] =>

)



)



)



[1] => Array

(

[file] => C:\xampp\htdocs\ecom\html\views\home.html

[line] => 14

[function] => mysqli_num_rows

[args] => Array

(

[0] =>

)



)



[2] => Array

(

[file] => C:\xampp\htdocs\ecom\html\index.php

[line] => 20

[args] => Array

(

[0] => C:\xampp\htdocs\ecom\html\views\home.html

)



[function] => include

)



)


 

 

Please what am I doing wrong. I didn't change anything except my URI. Thanks for rescuing me in advance.

 

 

 

Share this post


Link to post
Share on other sites

Hello. First of all, please use meaningful subject lines. Second, this is a fairly simple, standard error, the result of your database query not working. If you look in the output, you'll see an item named "error" which gives the specific problem. 

Share this post


Link to post
Share on other sites

Hi Larry et al, 

 

I have checked the database and found out that I have executed this command and it showed executed. I have got no expert knowledge to solve it cause I'm a newbie. Please assist.

 

Command:

 

 

" DELIMITER $$

CREATE PROCEDURE select_sale_items (get_all BOOLEAN)
BEGIN
IF get_all = 1 THEN 
SELECT CONCAT("O", ncp.id) AS sku, sa.price AS sale_price, ncc.category, ncp.image, ncp.name, ncp.price, ncp.stock, ncp.description FROM sales AS sa INNER JOIN non_coffee_products AS ncp ON sa.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE sa.product_type="other" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) )
UNION SELECT CONCAT("C", sc.id), sa.price, gc.category, gc.image, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole), sc.price, sc.stock, gc.description FROM sales AS sa INNER JOIN specific_coffees AS sc ON sa.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id WHERE sa.product_type="coffee" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) );
ELSE 
(SELECT CONCAT("O", ncp.id) AS sku, sa.price AS sale_price, ncc.category, ncp.image, ncp.name FROM sales AS sa INNER JOIN non_coffee_products AS ncp ON sa.product_id=ncp.id INNER JOIN non_coffee_categories AS ncc ON ncc.id=ncp.non_coffee_category_id WHERE sa.product_type="other" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) ORDER BY RAND() LIMIT 2) UNION (SELECT CONCAT("C", sc.id), sa.price, gc.category, gc.image, CONCAT_WS(" - ", s.size, sc.caf_decaf, sc.ground_whole) FROM sales AS sa INNER JOIN specific_coffees AS sc ON sa.product_id=sc.id INNER JOIN sizes AS s ON s.id=sc.size_id INNER JOIN general_coffees AS gc ON gc.id=sc.general_coffee_id WHERE sa.product_type="coffee" AND ((NOW() BETWEEN sa.start_date AND sa.end_date) OR (NOW() > sa.start_date AND sa.end_date IS NULL) ) ORDER BY RAND() LIMIT 2);
END IF;
END$$
DELIMITER ;

"

.

Share this post


Link to post
Share on other sites
[error] => PROCEDURE ecommerce1.select_sale_items does not exist

The original post indicates that the stored procedure does not exist. Are you sure you have it associated with the correct database? Try testing it in phpmyadmin with CALL select_sale_items(true) and CALL select_sale_items(false). If you dont have phpmyadmin, create a simple script which calls the stored procedure and echos out the data that will be returned.

 

This book is really for more intermediate programmers so you might want to refer to PHP and MySQL for Dynamic Websites - it includes a chapter that covers debugging techniques.

 

  • Upvote 1

Share this post


Link to post
Share on other sites
Thanks a load my man! Your insight help me a lot.  I managed to pinpoint the error. The base URI was pointing to  the database for knowledge is power (commerce1). I have change it. However,  I have a little problem, the site images are not loading. I know this is a minor error you can help me fix. You can't imagine how happy I am. you have made my day.

Share this post


Link to post
Share on other sites

Well I am happy to help but you have to help us help you.

the site images are not loading.

Presented with this problem and given that you've already experienced a problem with a database being incorrectly pointed to, it is clear that your first trouble shooting approach should be to look at how you are pointing to the location of the images.

 

If my site is not displaying correctly, I often look at the source code. Find the code that links to the image and click on on the link - you'll probably get a message indicating that the file does not exist. Check the folder for its existence - if you're sure there are no errors in the filename, then change the file path.

 

Learning strategies to debug saves you loads of time.

  • Upvote 1

Share this post


Link to post
Share on other sites

Margaux and Antonio, thanks a load. Your assistance helped me a lot. I have fixed the problem. But I have another one, don't be annoyed please. 

 

I downloaded the superfish.js and hoverintent.js and when I try to move my mouse to click on add_specific_coffee it disappears immediately. My mouse can't reach it at all. I did everything in the book but it's not working man.

 

I also have an undefined index sales_price in list_products3.html that is linked to browse.php. please assist in the best way forward.

 

Thanks

 

 

Find error below:

 

An error occurred in script 'C:\xampp\htdocs\ecom\html\views\list_products3.html' on line 60:
Undefined index: sale_price
Array

(

[0] => Array

(

[file] => C:\xampp\htdocs\ecom\html\views\list_products3.html

[line] => 60

[function] => my_error_handler

[args] => Array

(

[0] => 8

[1] => Undefined index: sale_price

[2] => C:\xampp\htdocs\ecom\html\views\list_products3.html

[3] => 60

[4] => Array

(

[GLOBALS] => Array

*RECURSION*

[_POST] => Array

(

)



[_GET] => Array

(

[type] => goodies

[category] => Mugs

[id] => 3

)



[_COOKIE] => Array

(

[sESSION] => db6f802f760980b5bb4fe7d9d480be29

[phpSESSID] => db6f802f760980b5bb4fe7d9d480be29

)



[_FILES] => Array

(

)



[live] =>

[contact_email] => you@example.com

[category] => Mugs

[sp_cat] => 3

[sp_type] => other

[type] => goodies

[page_title] => Goodies to Buy::Mugs

[dbc] => mysqli Object

(

[affected_rows] => 2

[client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $

[client_version] => 50008

[connect_errno] => 0

[connect_error] =>

[errno] => 0

[error] =>

[field_count] => 8

[host_info] => localhost via TCP/IP

[info] =>

[insert_id] => 0

[server_info] => 5.5.16

[server_version] => 50516

[sqlstate] => 00000

[protocol_version] => 10

[thread_id] => 932

[warning_count] => 0

)



[r] => mysqli_result Object

(

[current_field] => 0

[field_count] => 8

[lengths] => Array

(

[0] => 91

[1] => 19

[2] => 2

[3] => 14

[4] => 93

[5] => 44

[6] => 4

[7] => 2

)



[num_rows] => 2

[type] => 0

)



[header] => 1

[row] => Array

(

[g_description] => A selection of lovely mugs for enjoying your coffee, tea, hot cocoa or other hot beverages.

[g_image] => 781426_32573620.jpg

[sku] => O2

[name] => Red Dragon Mug

[description] => An elaborate, painted gold dragon on a red background. With partially detached, fancy handle.

[image] => 847a1a3bef0fb5c2f2299b06dd63669000f5c6c4.jpg

[price] => 7.95

[stock] => 22

)



)



)



)



[1] => Array

(

[file] => C:\xampp\htdocs\ecom\html\browse.php

[line] => 61

[args] => Array

(

[0] => C:\xampp\htdocs\ecom\html\views\list_products3.html

)



[function] => include

)



)

Share this post


Link to post
Share on other sites

Hey xto, I'm going to try to say this in the nicest way possible -  You're in danger of trying people's patience not because you ask questions, we like questions, but because you ask questions in a way that doesn't provide the information needed to try to answer them.

 

1. please read the forum guidelines - Look for the little grey text bottom right of most pages, labelled Guidelines

2. please post only RELEVANT code and error messages within code tags. We don't need to see the entire output from your error message. It's actually distracting. Use code tags which are on the edit bar and they look like <>

3. post the relevant CODE, you keep posting the error message but not any code.

4. You should start a new thread for each new question. One reason for doing so is that other people with the same question can search and find your thread. If your question is part of another thread, it won't be found and won't help others.

5. You're asking questions that you should be able to solve 1 because the level of  experience for this book expects you know some basic debugging strategies and 2. with a little bit of online searching you would get some pointers as to where to look for the cause of your error.

 

I really shouldn't answer your question given the above but ...

 

somewhere in your code you are referencing an array value using 'sale_price' as the index, which doesn't exist. I'm going to hazard a guess that you have a line that includes $row['sale_price']. From the error dump you posted, you will see there is no index 'sale_price' but there is one named 'price'. Given what info you've provided that's all I can help with. If this doesn't help solve the problem, start a new thread and post the code that is causing the error :)

  • Upvote 4

Share this post


Link to post
Share on other sites

It can have different meanings from what I understand. Both for building up the crowd for applause and to insult.

 

From Urban dictonary:

A gradual building of applause, usually starting with one person clapping slowly, and ending with an enthusiastic standing ovation. Generally shows approval for an underdog in a come from behind victory or after losing with pride intact.

 

It's absolutely pro Margaux. I tried to be funny, but I guess I had to explain my own joke in the end. :P

Share this post


Link to post
Share on other sites

No, I totally got it the whole time, Antonio. I was more joking than anything, but I suppose it's hard to read that nuance with just some words on a page.

Share this post


Link to post
Share on other sites

Thanks for the little bashing to be frank I never read the forum rules; didn't know one exists, was focused find answers to my problems. I assure you I will read it and follow up. Will try your suggestion and then read the forums guide lines. Thanks and cheers

  • Upvote 1

Share this post


Link to post
Share on other sites

Hi my men! please, I tried following the book steps in fixing the superfish and hoverintent. I downloaded the files and put the two .js files in js folder and the CSS file in the CSS folder. I also modified the path as I did for others, however, I can't click on the drop down menu to access it. Please, any clue on how to fix this will be appreciated. Thanks

Share this post


Link to post
Share on other sites
http://www.youtube.c...v=whytAReStUQ#!

I love this film!

 

xto - I couldn't get the superfish menu to work out of the box either and had to make some changes to the css.  Seriously, post this question in a new thread. Also maybe it should go in a different forum,(javascript or other) as the root cause is probably to do with the javascript or the css.

Share this post


Link to post
Share on other sites

Are "superfish" and "hoverintent" part of the e-commerce book? What are they?

Superfish is an implementation of a jquery plugin for dropdown menus that Larry implements in the coffee project in the ecom book. It makes use of another jquery plugin hoverintent to make for a nice user experience. Nothing to do with php.

 

xto - the book you refer to is very good, you'll learn loads of different programming strategies and techniques. I'd actually recommend reading it in order which is not what I did initially. Practically every chapter introduces you to new php functions which you will find very useful.

Share this post


Link to post
Share on other sites

Hmmmm! Sigh of relief at last. It's time to dig into the gold (PHP AND MYSQL FOR DYNAMIC WEBSITE). Larry, thanks for putting these stuffs in a book. Aside my men, Marg,Antonio et al, thanks for helping me dig deeper. See me in another tread soon. End Of Discussion (EOD) for this tread. Cheers

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...