View Full Version : Trouble Bookmarking PHP Page

05-23-2008, 05:44 AM
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:

// 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>";



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.

$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?

05-23-2008, 06:02 AM
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:

instead of

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

$query = "SELECT * FROM wwjitems WHERE item = '".$_GET['itemnum']."'";

05-23-2008, 07:37 AM
Awesome, exactly the solution I was looking for. Thanks, man.

05-23-2008, 07:48 AM
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).

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum