Jump to content
Larry Ullman's Book Forums

Part 3 Physical Products - Ch8 Creating A Catalog


Recommended Posts

Hi Larry/everyone, greetings.

 

When i click Coffee button in index.php, there are no images but text in the coffee page (http://localhost/physical_product/shop/coffee/), shown below:

 

*

*

*

*

 

CoffeeWouldn't you love a cup right now?

 

* Coffee

* Goodies

* Sales

* Wish List

* Cart

 

*

Dark Roast

 

Dark RoastOur darkest, non-espresso roast, with a full flavor and a slightly bitter aftertaste.

View All Dark Roast Products

*

Kona

 

KonaA real treat! Kona coffee, fresh from the lush mountains of Hawaii. Smooth in flavor and perfectly roasted!

View All Kona Products

*

Original Blend

 

Original BlendOur original blend, featuring a quality mixture of bean and a medium roast for a rich color and smooth flavor.

View All Original Blend Products

 

© - Clever Coffee, Inc.

Site designed by: Templates.com

 

 

 

In my win 7 computer, the stored procedure are stored successfully in Mysqladmin. The images and products folders are put in root directory (htdocs) with index.php.

 

Is there anything wrong with the PHP script in header.html?

 

Thanks for your kind help in advance.

 

phpmyadmin 3.2

php 5.3

mysql 5.1

editor: dreamweaver

Link to comment
Share on other sites

First, thanks for posting all the key information. Much appreciated. The cause of the problem is the directory structure. You say that the images and products folders are in the root directory, but are they really? Or are they in the physical_products directory (per your URL)? If it's the latter, then you need to change references in the header from /something to /physical_products/something. You'll also need to set a RewriteBase in the .htaccess file, just after turning the RewriteEngine on:

RewriteBase /physical_products/

Link to comment
Share on other sites

Hi Larry,

Many thanks for writing such a good book - I am new to e-commerce and found your book to be very helpful.

Here is my problem (i have done google search, but didn't work out solution :( feeling so frustrated:(( ):

Software used: Apache 2.2, php 5.3.5, MySql Server 5.1, Windows 7.

Working on catalogue, created database, populated tables, slightly modified code since my product has only 1 type (deleted if statements that determine type), even created page which shows me available Brands (I am using brands.php instead of shop.php, I adjusted .htaccess for this file name) so all procedures are working and I am getting info from database ok. Then I have a link which says <a href="browse/'.urlencode($row['brand_name']).'/'.$row['brand_id'].'"> , and when I put my cursor over the link on page in browser, then I can see that link should point to e.g localhost/emacs/html/browse/Canon/1 but when I press link my browser says that link is broken. When I am trying to load browse.php it shows error message (I have an impression that my script in brands.php (analog to your shop.php) do not pass variables to browse.php). On a top of this my Apache totally ignores rules that I set to rewrite url. I google it and everybody say you need to uncomment three lines, from which I have config file only one (and I did uncomment it):LoadModule rewrite_module modules/mod_rewrite.so, by the way I noticed that you use in .htaccess syntax 'mod_rewrite.c' but my apache conf file doesn't have such a file.

 

Here is my htaccess:

<IfModule mod_rewrite.so>

RewriteEngine on

# For sales:

RewriteRule ^brands/sales/?$ sales.php

# For the primary categories:

RewriteRule ^brands/([A-Za-z\+]+)/?$brand.php

# For specific products:

RewriteRule ^browse/([A-Za-z\+\-]+)/([0-9]+)$browse.php?&brand_name=$1&brand_id=$2

# For HTTPS pages:

RewriteCond %{HTTPS} off

RewriteRule ^(checkout\.php|billing\.php|final\.php|admin/(.*))$ https://%{HTTP_HOST}/$1 [R=301,L]

</IfModule>

here is my brands.php (analogue to your shop.php)

<?php

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

 

require(MYSQL);

$page_title="Brands Catalog - Shopping Area - Based in Dublin - Supplier of wide range of printer cartridges at the lowest prices in Ireland - Free next day delivery and 100% quality guarantee";

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

$r=mysqli_query($dbc,"CALL select_brands()");

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

if(mysqli_num_rows($r)>=1){

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

}else{

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

}

 

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

?>

here is list_brands.html:

 

<div class="main_brand"><fieldset><legend>If you can't find a toner...</legend><p>If you can't find brand that you are looking for in list below, <a href="mailto:ztischenko@emacs-enterprise.ie">email</a> us toner name you are looking for and we will come back to you on possibility to get it.</p></fieldset></div>

<div class="brand_d">

<ul class="brand_list">

<?php while ($row=mysqli_fetch_array($r,MYSQLI_ASSOC)){

echo '<li><fieldset><legend>'.$row['brand_name'].'</legend>'.'<div><a href="page.html"><img alt="Click to view all printers in this category" src="products/'.$row['image'].'"/></a>'.'There are toners for <a href="browse/'.urlencode($row['brand_name']).'/'.$row['brand_id'].'">'.$row['printer_count'].'</a>'.' '.$row['brand_name'].' printers listed on our website.</div>'.'</fieldset></li>';

}

?>

 

</ul>

</div>

 

and finally here is my browse.php:

<?php

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

$brand_name=$sp_brand=false;

if(isset($_GET['brand_name'],$_GET['brand_id'])&& filter_var($_GET['brand_id'], FILTER_VALIDATE_INT, array('min_range'=>1))){

$brand_name=$_GET['brand_name'];

$sp_brand=$_GET['brand_id'];}

 

if(!$sp_brand||!$brand_name){

$page_title='Error!';

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

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

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

exit();

}

$page_title='Buy'.$brand_name.' at the best prices in Ireland.';

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

require(MYSQL);

$r=mysqli_query($dbc,"call select_printers('$sp_brand')");

if(mysqli_num_rows($r)>=1){

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

}else{

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

}

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

?>

 

When I view browse.php in 'live code' view in Dreamviewer then I see error message from error.html.

 

Could you please help me? I spent smth like 8 hrs in a row and I seem not moving anywhere...

Many thanks in advance,

Regards

Zory

Link to comment
Share on other sites

Thanks for the nice words. As I wrote in my previous post to the original poster, I suspect the problem has to do with your directory structure (i.e., how the files are organized on your computer and what URLs you're using).

Link to comment
Share on other sites

well, I got brands.php to display images for items taken from database OK, my brands.php is in site root directory along with browse.php, everything seems to be working up to the moment when I am passing 'category' and 'id' to browse.php. This is for some reason do not work. I spent last 9 hrs trying to figure out why it is not working, could you (please,please,please) look at my code?

regards

Zory

Link to comment
Share on other sites

Hi Larry,

Thank you very much for your reply. I need your further help on the same problem.

 

Per your advice, 1)I checked the directory structure in my computer, it's the same layout as Figure 7.5 at page 173 (htdocs/physical_product folder/images folder or products folder.)

 

2)i added RewriteBase /physical_product/ in .htaccess file, and index.php in firefox browser looks normal.

 

3) i've tried to change references(from /something to /physical_products/somethingas you suggested) shown below, but the browser reads: Object not found in coffee page:

 

<li><a href="./physical_product/shop/coffee">Coffee</a> </li>

 

What else can i try to overcome the structure problem?

 

Look forward to your reply.

 

Here is body part of the header.html script in my computer, which i made a little change from your downloadable files.

 

 

<body id="page1">

<!-- header -->

<div id="header">

<div class="container">

<div class="wrapper">

<ul class="top-links">

<li><a href="./index.php" class="first"> <img alt="" src="./images/icon-home.gif" /></a></li>

<li><a href="./cart.php"><img alt="" src="./images/icon-cart.gif" /></a></li>

<li><a href="./contact.php"><img alt="" src="./images/icon-mail.gif" /></a></li>

<li><a href="./sitemap.php"><img alt="" src="./images/icon-map.gif" /></a></li>

</ul>

<div class="logo">

<h1><a href="./index.php">Coffee</a><span>Wouldn't you love a cup right now?</span></h1>

</div>

</div>

<ul class="nav">

<!-- MENU -->

<li><a href="./shop/coffee">Coffee</a> </li>

<li><a href="./shop/goodies">Goodies</a></li>

<li><a href="./shop/sales">Sales</a></li>

<li><a href="./wishlist.php">Wish List</a></li>

<li><a href="./cart.php">Cart</a></li>

<!-- END MENU -->

</ul>

</div>

</div>

<!-- content -->

<div id="content">

<div class="container">

<div class="inside">

Link to comment
Share on other sites

well, I got brands.php to display images for items taken from database OK, my brands.php is in site root directory along with browse.php, everything seems to be working up to the moment when I am passing 'category' and 'id' to browse.php. This is for some reason do not work. I spent last 9 hrs trying to figure out why it is not working, could you (please,please,please) look at my code?

regards

Zory

 

I can look at your code. However, as I've said twice now in this post, I don't think the problem is in the code but rather in your directory structure and URLs. Neither of which have you provided yet.

 

 

Hi Larry,

Thank you very much for your reply. I need your further help on the same problem.

 

Per your advice, 1)I checked the directory structure in my computer, it's the same layout as Figure 7.5 at page 173 (htdocs/physical_product folder/images folder or products folder.)

 

2)i added RewriteBase /physical_product/ in .htaccess file, and index.php in firefox browser looks normal.

 

3) i've tried to change references(from /something to /physical_products/somethingas you suggested) shown below, but the browser reads: Object not found in coffee page:

 

  • Coffee
  •  

    What else can i try to overcome the structure problem?

     

    If your directory structure is the same as that in the book, that's great, but your directory structure is not the same as in the book. In the book the files are in the Web root directory (htdocs), but you've placed everything within a subdirectory. This is fine, too, but you have to change all references accordingly. For example, the link to ./physical_product/shop/coffee is incorrect. The initial period means the link is relative to the current page, which won't often be the case. What you want instead is /physical_product/shop/coffee (as I wrote before), where the initial / means to start in the Web root directory.

    Link to comment
    Share on other sites

    Hi Larry, many thanks for your replay,

    I decided to move on and leave url transformation for later, looks like script passing variables ok, if I am coding brands.php?brand=... instead of brand/canon/ as was intended at the beginning. I am worried about security issues thus I will have to come back to this issue when site goes live.

    So if you will have a thought why would apache 2.2 reject to obey rewrite rules that i have defined in .htaccess file in root directory - that would be so much appreciated!

    My directory structure is on image enclosed.sitestructure.jpg

     

    Many thanks!

    Regards

    Zory

    Link to comment
    Share on other sites

    So if you will have a thought why would apache 2.2 reject to obey rewrite rules that i have defined in .htaccess file in root directory - that would be so much appreciated!

     

    Apache would ignore .htaccess files if httpd.conf (the primary configuration file) isn't set to allow overrides (i.e., changes) within directories.

    Link to comment
    Share on other sites

    Hi Larry,

    Many thanks for your replay,

    I have following in http.conf :

     

    <Directory "C:/websites">

     

    AllowOverride All

     

    and this too:

    DocumentRoot "C:/websites"

     

    <Directory />

    Options All

    AllowOverride All

    </Directory>

    Still - no luck with rewrite module.

    Regards

    Zoryana

    Link to comment
    Share on other sites

    Larry,

    Followed by your more detailed advice, finally all the images of shop/coffe page can be viewed in browser. :D

     

    Thank you very much for your patience and time. I'm so glad that I can move on to Chapter 9 next Monday with your kind help.

    • Upvote 1
    Link to comment
    Share on other sites

    Hi, Larry/All,

    My question on Ch 8, Coffee example.

    in my browser page (http://localhost/physical_product/browse/goodies/Mugs/3), error message is displayed in a box:

     

    Error!

    Unfortunately a system error has occurred. Please use the links at the top of the page to continue shopping. We apologize for the inconvenience. .

     

    How to solve it? Appreciate your help.

     

    stored procedure is stored successfully.

    PHP 5.3

    Mysql 5.1

    win 7

    Dreamweaver

    Link to comment
    Share on other sites

    Followed by your more detailed advice, finally all the images of shop/coffe page can be viewed in browser. :D

     

    Thank you very much for your patience and time. I'm so glad that I can move on to Chapter 9 next Monday with your kind help.

     

    You're quite welcome. Glad it's working now and thanks for letting me know.

    Link to comment
    Share on other sites

    My question on Ch 8, Coffee example.

    in my browser page (http://localhost/phy.../goodies/Mugs/3), error message is displayed in a box:

     

    Error!

    Unfortunately a system error has occurred. Please use the links at the top of the page to continue shopping. We apologize for the inconvenience. .

     

    How to solve it? Appreciate your help.

     

    Okay, so you see that result if this conditional is not true:

    if (!$type || !$sp_type || !$sp_cat || !$category) {

     

    So to debug this, just before that line, I would echo out the values of those four variables.

    Link to comment
    Share on other sites

    Hi Larry,

    My continued question on Error message in Browse.php

     

    Thanks for your reply. I've been trying to make browse.php happen these days.

     

    Following you advice, I put the four values of variables below before the script line:

     

    $type = "coffee";

    $sp_type = "coffee";

    $category = 'coffee';

    $sp_cat = 'coffee';

    echo $type;

    echo $sp_type;

    echo $sp_cat;

    echo $category;

     

    Then the message reads in the browser:

    coffee

    Unfortunately there are no products to list in this category. Please use the links at the top of the page to continue shopping. We apologize for the inconvenience.

     

    Are the variables functional in browse.php? If not, what else shall i try to debug next?

    Thanks for your time.

    Link to comment
    Share on other sites

    Yeah, that's not really the solution or what I meant. In fact, it's not a solution at all. What you did is created those variables (and gave two of them inappropriate values). What you should do is print out what values the variables have. That should be determined by code earlier in the scripot.

    Link to comment
    Share on other sites

    Hi Larry,

    Seek your continued help in browse.php in Chapter8.

     

    When i remove the following from browse.php:

    // If there's a problem, display the error page:

    if (!$type || !$sp_type || !$sp_cat || !$category) {

    $page_title = 'Error!';

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

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

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

    exit();

    }

     

    the message in browse.php browser reads:

    An error occurred in script 'C:\xampp\htdocs\physical_product\browse.php' on line 47:

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

     

    line 47 in browse.php is:

    if (mysqli_num_rows($r) > 0) {

     

    The stored procedure is well run in my win 7 computer, I have changed nothing on stored procedure and database.

     

    What does the message above tell me? What shall i do to debug it? Thank you for your time.

     

    php 5.3

    mysql 5.1

    win 7

    dreamweaver

    Link to comment
    Share on other sites

    Why would you remove that? That's the code that's supposed to work. Do you not understand what I mean by "print out what values the variables have"? It's critical, fundamental debugging. As I wrote two posts ago, just print out the values of the variables before that line. To be more explicit, add this code to your script (again, before the aforementioned line):

    
    echo "<p>Type = $type <br />
    SP Type = $sp_type <br />
    SP Cat = $sp_cat <br />
    Category = $category </p>";

     

    That's all I mean. Just print out the values of the variables so you can see what they are. Don't assign values to the variables and don't remove any code, just print out the values of the variables.

     

    Since that conditional is true, it means one of those variables doesn't have a proper value. The goal, then, is to determine which. Once you do that, you can work your way backwards to where the variables are assigned values to see where the problem is.

    Link to comment
    Share on other sites

    Larry,

    I'm very grateful for your time and patience to show me in such a detailed advice on debugging skill. :) I will try it again later.

    i'm now busying with curl technology required in billing.php page. Luckily I've found I'm able to learn it from your book -PHP 5 Advanced (2dn edition).

    Link to comment
    Share on other sites

     Share

    ×
    ×
    • Create New...