Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble Bookmarking PHP Page

    I apologize for how confusing this might get. I'm using PHP to pull items from a SQL database. This is the relevant portion of the code from my main results page:

    PHP Code:
    // see if any rows were returned
    if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another


    echo "<table width=100% border=0 cellspacing=0 cellpadding=0 class=box_width_cont product><tr>";
    $i 0;
    while(
    $row mysql_fetch_row($result)) {

    if (
    $i == 3)
    {
    echo 
    "</tr><tr>";
    $i 0;
    }

    echo 
    "<td width=33%>";

    echo 
    "<a class='thumbnail' href='javascript:void(0)'><img src='images/3stone/rings/".$row[0]."fronts.jpg'>";

    echo 
    "<span><img src='images/3stone/rings/".$row[0]."front.jpg'></span></a><br>";

    echo 
    "<font color=#855b63><b>".$row[1]."<br>".$row[2]."<br>".$row[6]." Cut<br>Size: ".$row[3]."</b><br><br></font><font color=#855b63 size=3><b>".$row[9]."</b></font><br><br>";

    echo 
    "<form action='details.php' method='post'><input type='image' src='images/button_details.gif' name='0' value='".$row[0]."'></form><br><img height='2' src='images/spacer.gif'><br><img src='images/button_add_to_cart1.gif'><br><br><br>";

    echo 
    "</td>";

    $i++;

    }



    echo 
    "</table>";


    As you can see, I have a details button under each row. I'm using a form POST method to send $row[0], which is the item number, to details.php when the button is clicked. Here is the query from details.php with the variable plugged in.

    PHP Code:
    $query "SELECT * FROM wwjitems WHERE item = '".$_POST["0"]."'"
    Details.php is a page that returns just one result with more details on that particular item. Everything works great, with one little problem. When someone bookmarks details.php and comes back later, they get a blank page. Is there any way around this, or will I have to use a different method for creating the single item page?

  • #2
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ever considered using $_GET variables instead of $_POST?
    that way you can make your form action

    <form action="details.php?itemnum=$row[0]" method="post">

    and call the item number anytime you need it from a $_GET operation.
    that way when a user bookmarks a page he will bookmark it as:
    yoursite.com/details.php?itemnum=[numberhere]

    instead of
    yoursite.com/details.php

    that way when he calls that page back, php will still have that $_GET variable to call the item ID off.

    For example your mysql query would look kinda like
    PHP Code:
    $query "SELECT * FROM wwjitems WHERE item = '".$_GET['itemnum']."'"
    Last edited by elementis0; 05-23-2008 at 06:07 AM.

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome, exactly the solution I was looking for. Thanks, man.

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    If you're posting the form anyway, there's no real advantage to making it a $_GET variable over using the form inputs. You should change the name from '0' to 'itemnum' though, if you're going to do that. Also, make sure you always sanitize user input($_GET/$_POST/$_COOKIE).


  •  

    Posting Permissions

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