I am developing an eCommerce site for books.When user search for specific book category then the books related that category is fetched from database using php and mysql and shown in a table with buy now button.When user click on buy button for specific ISBN number then it is redirected to purchase page where user has to give his/her billing info for selected ISBN number.But the problem is that On clicking Buy Now button that particular ISBN is not passed in purchase page. Here is my searchresult.php code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<table class="table table-condensed" style="margin-bottom:0px">
<thead>
<tr class="cart_menu">
<td class="image"></td>
<td class="description">Book Name</td>
<td class="description">ISBN Number</td>
<td class="description">Price</td>
<td></td>
</tr>
</thead>
<tbody>
<?php
@$query=("SELECT * from book where category='computer science'");
@$res=mysql_query($query);
while(@$row=mysql_fetch_assoc($res)) { ?>
<tr>
<td class="cart_description">
<h5><?php echo $row['name'] ?></h5>
</td>
<td class="cart_description">
<h5><?php echo $row['ISBN'] ?></h5>
</td>
<td class="cart_description">
<h5>$<?php echo $row['price'] ?></h5>
</td>
<td>
<?php echo'<a class="btn btn-primary" name="ISBN" style="margin-top:0px;" href="cart.php?ISBN=' . $row['ISBN'] . '">Buy Now</a>';?>
</td>
</tr>
<?php } ?>
</tbody></table>
</body>
</html>
When user click on Buy Now button It is redirected to cart.php
Where I am fetching action data from searchresult.php ie ISBN number as:
<?php echo $_GET['ISBN']; ?>
But after reLoading page the ISBN number is vanished.
Please help me to pass ISBN number and store there till the purchase of book is complete.
As people are commenting, I think you used the word refresh incorrectly. If you want to keep the items in the cart in GET or POST variables that your choice. I personally think its crazy, you should should be putting them in a table somewhere. What happens when someone jumps to the contact page by manually typing....everything is going to be gone?
Regardless, if you are losing the ISBN, simply output it as a hidden form input. Then when they submit the form on the cart page it will be posted along with it. You can also use $_REQUEST to allow for both post and get variables.
mysql_query is depriciated. You need to stop using it, pdo or mysqli are your options.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.