SitePoint Sponsor

User Tag List

Page 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 51
  1. #26
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    I removed the index.php but the link still fails.

    The link with just the product_id works. Is it possible to echo something into the link but for it to be ignored from a query?


    Code:
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^products/product/([a-zA-Z0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    </IfModule>

  2. #27
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    It might be easier just to test that the rewrite rule is working and passing the product id by typing in a URL for now. The URL I've been using to test on my system is products/product/123/chest-of-drawers-oak, which I'm typing in manually.

    From within your products.php, trying doing var_dump($_GET); to see what values (if any) are being passed to your script. Could you also paste the contents of your .htaccess please?

  3. #28
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks,

    Unfortunately I still cant get this to work. Im not sure what the code should be doing it. Should it be ignoring the $name variable but only count the $product_id

  4. #29
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    If you could post the code from your .htaccess file, and from your product.php file it would make it easier to try and find the problem.

  5. #30
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Please see following...


    Code:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [L]
    
    # Disable directory listing from this point
    Options -Indexes
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^products/product/([a-zA-Z0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    RewriteRule ^ index.php [L]
    </IfModule>









    Code:
    <div id="menulowerlinkscell">
    <div class="menulowerlinks">
    <a href="/products/nameproductscategorised/pine" rel="nofollow" class='lowermenulink'>Pine Furniture</a>
    </div>
    <div class="menulowerlinksinner">
    <a href="/products/nameproductscategorised/oak" rel="nofollow" class='lowermenulink'>Oak Furniture</a>
    </div>
    <div class="menulowerlinksinner">
    <a href="/products/nameproductscategorised/mahogany" rel="nofollow" class='lowermenulink'>Mahogany Furniture</a>
    </div>
    <div class="menulowerlinks">
    <a href="/products/nameproductscategorised/white" rel="nofollow" class='lowermenulink'>White Furniture</a>
    </div>
    </div>
    
    <div id="breadcrumbscell">
    You Are Here: <a href="/index.php" rel="nofollow"  class='breadcrumbslink'>Home</a> > <?php echo $row ['name'];?>
    </div>
    <div id="singleproductcell">
    
    <div class="productsborder">
    
    <div class="singleproductimageborder"><a rel="nofollow" href="<?php echo $row['link'];?>" target="_blank"><img src="<?php echo $row['image_link'];?>"  alt="<?php echo $row['name'];?>" /></a></div>
    
    
    
    
    <div class="productrightcell"><div class="singleproductdescriptionborder"><a rel="nofollow" href="<?php echo $row['link'];?>" target="_blank" class='productlink' ><?php echo $row['name'];?></a></div> 
    <div class="singleproductpricingborder">
    Price <?php echo $row['price'];?> - Save <?php echo $row['discount'];?>%<br /></div><div class="productdescriptionborder"><div class="productdetailsabout">About</div><?php echo (strlen($row['description']) < 1000) ? $row['description'] : trim(substr($row['description'], 0, 1000)) . "..."; ?></div>
    <div class="productdescriptionborder"><?php echo (strlen($row['fulldescription']) < 1000) ? $row['fulldescription'] : trim(substr($row['fulldescription'], 0, 1000)) . "..."; ?></div></div>
    </div>
    </div>
    <div class="productclearanceareas">
    <div class="productclearanceareastitle">
    Clearance Range
    </div>
    <div class="productclearanceareascell">
    <?php
    
    $query = mysql_query("SELECT * FROM productdbase ORDER BY discount DESC LIMIT 3");
    while($row = mysql_fetch_array($query)) {
        ?>
    
    
    
    
    <div class="productrangeborder">
    
    
    <div class="productsdetailsborder"><a href="http://ukhomefurniture.co.uk/products/product/<?php echo $row['product_id']; ?>" class='productlink' ><?php echo $row['name']; ?></a></div>
    
    <div class="productimageborder"><a href="http://ukhomefurniture.co.uk/products/product/<?php echo $row['product_id']; ?>" ><img src="<?php echo $row['image_link']; ?>" alt="<?php echo $row['name']; ?>" /></a></div>
    
    
    
    
    
    
    <div class="priceborder">Price &pound;<?php echo $row['price']; ?><br /></div><div class="discountborder">Save <?php echo $row['discount']; ?>%<br /></div></div>
    
    
    <?php
    }
    
    ?>
    </div>
    <div class="productclearancearticles">
    <div class="productclearancearticlestitle">
    Latest Articles
    </div>
    <div class="productclearancearticlesticlesborder">
    
    <?php
    
    $query = mysql_query("SELECT * FROM articles ORDER BY ID DESC LIMIT 5");
    while($row = mysql_fetch_array($query)) {
        ?>
    
    <div class="productclearanceaarticleslinks"><a href="/articles/article/<?php echo $row['ID']; ?>" class='articleslink' rel="nofollow" ><?php echo $row['title']; ?></a> | <a href="/articles/articlesfiltered/<?php echo $row['articlecategory']; ?>" rel="nofollow"  class='articlesfilterlink'><?php echo $row['articlecategory']; ?></a></div>
    
    <?php
    }
    
    ?>
    
    </div>
    </div>
    </div>
    </div>
    </div>

  6. #31
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    OK, so your .htaccess file needed some changes to get it working on my machine. Here's what I did:
    Code:
    Options -Indexes
    Options -MultiViews
    Options +FollowSymLinks
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    # Rewrite Rules
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    </IfModule>
    As for the php code you shared, I couldn't see any code there for retrieving the product ID from $_GET?
    Last edited by fretburner; Jul 12, 2013 at 10:23. Reason: Removed RewriteBase line specific to my local machine

  7. #32
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cheers mate,

    This is the get code...


    Code:
    <?php
    if (isset($_GET['product_id']))
    $product_id = mysql_real_escape_string($_GET['product_id']);
    $sql = "SELECT * FROM productdbase WHERE product_id = '$product_id'";
    $res = mysql_query($sql) or die(mysql_error());
    $row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row
    $num_rows = mysql_num_rows($res); // check to see if any results were found, just in case someone puts an ID in the url without clicking on your link
    ?>

  8. #33
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    That looks like it should work OK in combination with the changes to your .htaccess file.

  9. #34
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I did change the htaccess file but it doesn't work.

    Should I be using the product_id first. I did try that but it still doesn't work.

  10. #35
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Should I be using the product_id first. I did try that but it still doesn't work.
    Not sure what you mean?

    Can you try putting var_dump($_GET); at the top of your product.php file and see what you get?

  11. #36
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The vardump produces this

    array(1) { ["product_id"]=> string(4) "6550" }

    Sorry, should my link be .com/red-widget/12345 or .com/12345/red-widget

  12. #37
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    The vardump produces this

    array(1) { ["product_id"]=> string(4) "6550" }
    That's good, so the rewrite rule is passing through the value to your script OK. One thing I did notice about your PHP code is that you're missing the braces from your IF statement. Try this and see what it gives you:
    PHP Code:
    if ($product_id filter_input(INPUT_GET'product_id'FILTER_SANITIZE_NUMBER_INT)) {
        
    $sql "SELECT * FROM productdbase WHERE product_id = $product_id";
        
    $res mysql_query($sql) or die(mysql_error());
        
    $row mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row
        
    var_dump($row);

    Note that I've used filter_input to get and filter the value from $_GET, making sure that only an integer (whole number) can be passed into the script.


    Quote Originally Posted by justlukeyou View Post
    Sorry, should my link be .com/red-widget/12345 or .com/12345/red-widget
    With the current rewrite rule, your URLs should be in the format example.com/products/product/12345/red-widget

  13. #38
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Still no luck with that Im afraid. Many thanks for your help so far.

    What part of this code blocks the name of the product from being read?

    Code:
     RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]

  14. #39
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Still no luck with that Im afraid.
    What response did you get from the var_dump of the db result? Because from the information you've provided, the problem is related to pulling the correct info out of the DB. As I stated before, the rewrite rule looks to be working properly, as you can see from the results of doing var_dump($_GET).

    Quote Originally Posted by justlukeyou View Post
    What part of this code blocks the name of the product from being read?

    Code:
     RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    It doesn't block it, it just doesn't pass it to the script. This part ([0-9]+) captures the product id number, which is then passed to your script as the value of product_id, by this part product_id=$1 (The $1 signifies the first match, in this case the product id - the product name would be $2)

  15. #40
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    The vardump displays everything from the database for this pirticular item.

  16. #41
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    Hi,

    The vardump displays everything from the database for this pirticular item.
    Erm, OK, so doesn't that mean that it's working then?

  17. #42
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Sorry,

    I meant the link doesn't work. Whenever I insert the name with hyphens this link doesn't work.

  18. #43
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Can you post an example of a link that doesn't work for you?

  19. #44
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I have tried both of these

    .co.uk/products/product/clearance---hatherley-high-gloss-2-drawer-bedside-chest-in-walnut-and-red/6550

    .co.uk/products/product/6550/clearance---hatherley-high-gloss-2-drawer-bedside-chest-in-walnut-and-red

  20. #45
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    .co.uk/products/product/6550/clearance---hatherley-high-gloss-2-drawer-bedside-chest-in-walnut-and-red
    That's really strange. I'm using the same .htaccess as I posted earlier, and the link works fine for me... it passes through the product ID with no problem.

  21. #46
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Its very strange. I deleted everything from the htaccess file so it was blank it and it had no impact on my site. The 404 page even appeared.

  22. #47
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by justlukeyou View Post
    I deleted everything from the htaccess file so it was blank it and it had no impact on my site. The 404 page even appeared.
    For sure, without the rewrite rules then the product URL just wont work.

    If you put the contents of .htaccess back, and put var_dump($_GET) back at the top of product.php and try the URL again, what do you get now?

  23. #48
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    This is what echoes when I visit the page without the product name in the link.

    Code:
    array(15) { ["product_id"]=> string(4) "6550" ["id"]=> string(9) "721268544" ["link"]=> string(57) "com/pclick.php?p=721268544&a=98057&m=495" ["name"]=> string(73) "Clearance - Hatherley High Gloss 2 Drawer Bedside Chest in Walnut and Red" ["linkname"]=> string(73) "clearance---hatherley-high-gloss-2-drawer-bedside-chest-in-walnut-and-red" ["rrp"]=> string(4) "0.00" ["sell_price"]=> string(5) "27.19" ["discount"]=> string(5) "89.00" ["image_link"]=> string(56) "721268544.jpg" ["furniture_group"]=> string(0) "" ["category_name"]=> string(0) "" ["merchant_category"]=> string(0) "" ["fulldescription"]=> string(0) "" ["price"]=> string(5) "27.19" ["merchant"]=> string(13) "Furniture 123" } array(1) { ["product_id"]=> string(4) "6550" }

    This is the htaccess file...

    Code:
    Options -Indexes
    Options -MultiViews
    Options +FollowSymLinks
    
    # Prevent viewing of htaccess file
    <Files ~ "^\.ht">
    order allow,deny
    deny from all
    satisfy all
    </Files>
    
    # Error Pages
    ErrorDocument 404 /404-error.php
    
    # Rewrite Rules
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^([a-z]+)/([a-z\-]+)$ /$1/$2.php [QSA,L]
      RewriteRule ^products/product/([0-9]+)/(.*)$ products/product.php?product_id=$1 [QSA,L]
    </IfModule>

  24. #49
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,438
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    OK, but what happens when you visit the full URL (ie. with the product name included in the link)?

  25. #50
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It continues to go to the 404 page.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •