Jump to content
Larry Ullman's Book Forums

Coffee Shop Tutorial:Menu Links Not Working


Recommended Posts

PHP Version 5.2.17

MySQL Version 5.0.91-log

 

I am thankful to be able to have an online community for Larry Ullman's great tutorials. I have finished "Knowledge Is Power" and am working on the physical products tutorial. Thank you Larry for your insight in knowing how to break complicated syntax into understandable working solutions.

 

Now to my question. I am almost positive I have followed every step throughout the Effortless E-Commerce tutorial. The site I have the tutorial files is at http://www.phppond.c.../html/index.php

 

As you can see, no links are working, even though the address seems correct. For example: The "Coffee" link on the index page, when clicked goes to http://www.phppond.com/shop/coffee/

 

I know I am missing something. I have checked the header.html file to check the menu links. I have checked the config.inc.php file to make sure the URI, URL, etc is correct.

 

I have used php for almost a year now, self taught by books, and have checked everything I can think of to no avail. Please be patient with me as I am willing to learn step by step and research everything I know before I ask for help. I have searched the Effortless E-Commerce thread also and have not found the solution. Or maybe I came across it and do not understand what I need to do. I can post whatever files to show you my coding.

 

Thanks,

Stephen.

Link to comment
Share on other sites

This is my .htaccess file in my html root directory:

 

 

<IfModule mod_rewrite.c>

RewriteEngine on

# For sales:

RewriteRule ^shop/sales/?$ sales.php

# For the primary categories:

RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1

# For specific products:

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

# For HTTPS pages:

RewriteCond %{HTTPS} off

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

</IfModule>

 

 

 

I think it is correct just as on page 176 in the book. Maybe something is wrong somewhere else. Thanks for your response Craig.

Link to comment
Share on other sites

Also, this is my .htaccess file in my includes folder:

 

 

# Disable directory browsing:

Options All -Indexes

# Prevent folder listing:

IndexIgnore *

# Prevent access to any file:

<FilesMatch "^.*$">

Order Allow,Deny

Deny from all

</FilesMatch>

Link to comment
Share on other sites

Per the forum rules, never, ever post a message like this last one. If your post doesn't ADD anything to the conversation, it shouldn't be made.

 

As for your problem, the issue is that you've installed the site in a subdirectory of your server: ex1/html. The .htaccess folder must go in that html folder. And your links need to be changed to /ex1/html/whatever. You'll also need to do that with your images and CSS and such as well.

Link to comment
Share on other sites

Thanks for the response, it will not happen again.

 

I got rid of the subdirectory and just uploaded everything in the subdirectory such as html, private, mysql.inc.php.

My menu links in the header.html is as follows:

 

 

<!-- MENU -->

<li><a href="<?php echo BASE_URL; ?>shop/coffee/">Coffee</a></li>

<li><a href="<?php echo BASE_URL; ?>shop/goodies/">Goodies</a></li>

<li><a href="<?php echo BASE_URL; ?>shop/sales/">Sales</a></li>

<li><a href="<?php echo BASE_URL; ?>wishlist.php">Wish List</a></li>

<li><a href="<?php echo BASE_URL; ?>cart.php">Cart</a></li>

<!-- END MENU -->

 

I also changed my config to

 

 

// Determine location of files and the URL of the site:

define ('BASE_URI', '/home/content/68/7344768/html/');

define ('BASE_URL', 'http://www.phppond.com/html/');

define ('MYSQL', BASE_URI . 'mysql.inc.php');

 

The links are still not working at http://www.phppond.com/html/

Link to comment
Share on other sites

I understand what your saying. So if I upload the files in the html directory and just have www.phppond.com/wishlist.php isn't the mysql.inc.php script located outside the html directory, so how would the files work? Would I need to move the mysql.inc.php script inside the root directory?

Link to comment
Share on other sites

update:

 

I just uploaded the files in the html directory to my root domain phppond.com. I also moved mysql.inc.php to root.

I changed the config to:

 

 

define ('BASE_URI', '/home/content/68/7344768/html/');

define ('BASE_URL', 'http://www.phppond.com/');

define ('MYSQL', BASE_URI . 'mysql.inc.php');

 

Based on everything I did above the wishlist and cart links are showing now but with an error:

 

An error occurred in script '/home/content/68/7344768/html/cart.php' on line 81:

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

 

The coffee, goodies, and sales links are still not working http://www.phppond.com/shop/coffee/.

Link to comment
Share on other sites

The .htaccess is in the root directory. I have gotten rid of all subdirectories. I do not know much about the .htaccess file or how to change the file except for the explanation in your book. The .htaccess file in my root directory is in my post #3 above. I also have an .htaccess file in the includes folder. The code for that .htaccess file is in post #4 above.

Link to comment
Share on other sites

Okay, then I think the next step is to confirm that .htaccess is working at all. I'd change the root .htaccess file to just this:

 

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^test/$ index.php
</IfModule>

Then go to http://www.phppond.com/test/ That should take you to the index.php page. If not, then you'll need to talk to your hosting company about allowing for .htaccess overrides.

Link to comment
Share on other sites

I changed the root .htaccess file to what you told me above. I also fixed the mysql error on the index.php page. Now if you go to this link http://www.phppond.com you will see that the index.php page is now showing fully, except that the sale item links are not working.

Only the wishlist and cart links are showing with an array error:

 

An error occurred in script '/home/content/68/7344768/html/cart.php' on line 81:

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

 

If you go to http://www.phppond.com/test/ the home page is showing with an array error and no style.

 

So, it seems like .htaccess privileges are granted.

Link to comment
Share on other sites

Yes, it seems like .htaccess is working. I'd now change it to just this:

<IfModule mod_rewrite.c>
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1
</IfModule>

 

Then you can make sure that the sales and shop pages are working.

 

As for that error, that's likely because your stored procedure isn't working. You'll need to apply the standard PHP-MySQL debugging techniques to determine why.

Link to comment
Share on other sites

I just changed the .htaccess root file to what you said above and no changes took place. The links are still the same.

 

 

Thanks for the tip on the stored procedures, I have read countless threads on this and really need to take some time and understand how to fix that deathly parameter 1 error. I remember I got frustrated last time with another project and just switched mysqli to mysql and it worked.

Link to comment
Share on other sites

That's very strange, because that .htaccess should work. Could you post the entire contents of your root-level .htaccess file here?

 

Also, just so you know, just switching from MySQL Improved functions to MySQL standard functions shouldn't be a solution to problems.

Link to comment
Share on other sites

Sorry for the delay. My root .htaccess is below:

 

<IfModule mod_rewrite.c>
RewriteEngine on
# For sales:
RewriteRule ^shop/sales/?$ sales.php
# For the primary categories:
RewriteRule ^shop/([A-Za-z\+]+)/?$ shop.php?type=$1
</IfModule>

Link to comment
Share on other sites

That was the trick. All the pages are at least showing content on the pages now. Thank you.

 

Questions:

1. Can you please explain: How did Options -MultiViews cause the pages to be displayed?

2. Cannot get my header.html style to work on shop/sales and shop/goodies.

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

3. Still searching for parameter 1 error solution as stated above.

 

Here is the site now with the newly implemented solutions you recommended.

http://www.phppond.com

Link to comment
Share on other sites

Questions:

1. Can you please explain: How did Options -MultiViews cause the pages to be displayed?

 

Here's the explanation from the Apache documentation:

 

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

 

 

2. Cannot get my header.html style to work on shop/sales and shop/goodies.

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

 

That's because you're using a relative path. With shop/sales, Apache is acting like sales is in a subdirectory, so the reference doesn't work. This is why I use absolute references in the book.

 

3. Still searching for parameter 1 error solution as stated above.

 

That's a very basic and common error that means your query isn't returning any results. You'll need to apply the standard PHP-MySQL debugging techniques to determine why.

Link to comment
Share on other sites

I should add politely that the book does require comfort with PHP at an intermediate level. If you are having problems with relative paths and error messages like that. It may be more worth your while to read "PHP and MySQL" before tackling this book as some parts of it are quite complicated and technical.

Link to comment
Share on other sites

Thank you Larry and Jonathan. I do not understand the following:

 

Cannot get my header.html style to work on shop/sales and shop/goodies.

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

 

I am using exactly what is in the book on page 211 which is my coding above which is relative path.

 

An example of absolute path would be include('http://www.phppond.com/includes/header.html');

 

Is this right?

Link to comment
Share on other sites

Sorry, my fault. That code is from the book and is okay, because it's a relative path in PHP. You can't use relative paths in the HTML while using mod_rewrite. The absolute path you posted is an absolute path, but you wouldn't include something in PHP using HTTP.

 

If you looked at the HTML source code of, say, shop/sales, you'd see that the header IS being included. The problem is your CSS file isn't being included. That's because you're using a relative path to it, which you can't do.

Link to comment
Share on other sites

 Share

×
×
  • Create New...