Page 1 of 1

Trouble Bookmarking PHP Page

Posted: Thu May 22, 2008 10:21 pm
by stragglerat
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:

Code: Select all

 
// 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&#058;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.

Code: Select all

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

Re: Trouble Bookmarking PHP Page

Posted: Thu May 22, 2008 10:31 pm
by nowaydown1
Using $_GET instead of $_POST will allow your users to bookmark whatever it is they're viewing. If ugly urls are a problem you could always use a rewrite rule to have something like /details/1 instead of details.php?someID=1. Also, make sure you are cleaning anything provided to you in your superglobal. Otherwise, you'll have SQL injection issues on your hands.

Re: Trouble Bookmarking PHP Page

Posted: Thu May 22, 2008 10:40 pm
by stragglerat
Seeing as how I'm a PHP rookie, a lot of that was slightly confusing ;). Where would I put the GET? Would I have to change my form that contains the details button?

Re: Trouble Bookmarking PHP Page

Posted: Fri May 23, 2008 12:43 am
by mhonnphp
stragglerat wrote:Seeing as how I'm a PHP rookie, a lot of that was slightly confusing ;). Where would I put the GET? Would I have to change my form that contains the details button?

at your FORM METHOD! change it to GET
and to get the variables pass by your form use $_GET['FORM ELEMENT NAME']

you can also refer here .... http://www.w3schools.com/php/php_get.asp