php code to manage shopping cart... question here.
Posted: Sat Oct 15, 2011 12:50 pm
Hi there, and thanks for your help.
I have a shopping cart on my website that is working not too bad. Not too bad until i tried to insert a search fonction to it.
what i dont like is, let say i make a search with the word electrical , the system show only item that has electrical in the description (and this is ok), but if i click on my add to cart button, it does add to the cart, but it does refresh the page and i am back showing all the items (like if there was no search done) so if i want to continue searching in the electrical, i have to type "electrical" again in the search field...
I would like it to work the same way as when you click the back button (back button of the browser) it brings you back where you were, at the same place on the page, with the same search word in the search field....
I have been searching on this without success.
this is a simple expaination of my page.php
>> the following form is located at the top of the page, first form
<form id="form1" name="form1" method="post" action="">
Search Key :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo $varsearch; ?> >
</form>
then in the middle of the page, i have a "while" command that read the whole database and make a form for each item
while ($db_field = mysql_fetch_assoc($result)) {
$is_search = stristr($desc, $varsearch);
if($is_search !== FALSE) {
Echo " <P><FORM NAME=order ACTION=\"managecart.html\" onSubmit=\"AddToCart(this);\"> ";
Echo " <input type=\"image\" src=\"./images/acheter.gif\" border=0 value=\"Add to Cart\" align=top> ";
Echo " </FORM> ";
}
}
so basically here is makes a <form> for each item that make the stristr() different than false (this is fine)
It make no difference if ACTION=magementcart.html is in the <form> or not... so when it execute the
addtocart(this) and come back, it refresh the page with all the items in inventory.... this is what i dont like because the customer has to retype in the search field to continue their shopping.
thanks for your help
I have a shopping cart on my website that is working not too bad. Not too bad until i tried to insert a search fonction to it.
what i dont like is, let say i make a search with the word electrical , the system show only item that has electrical in the description (and this is ok), but if i click on my add to cart button, it does add to the cart, but it does refresh the page and i am back showing all the items (like if there was no search done) so if i want to continue searching in the electrical, i have to type "electrical" again in the search field...
I would like it to work the same way as when you click the back button (back button of the browser) it brings you back where you were, at the same place on the page, with the same search word in the search field....
I have been searching on this without success.
this is a simple expaination of my page.php
>> the following form is located at the top of the page, first form
<form id="form1" name="form1" method="post" action="">
Search Key :<input type="text" name="varsearch" id="varsearch" size="40" value = <?php echo $varsearch; ?> >
</form>
then in the middle of the page, i have a "while" command that read the whole database and make a form for each item
while ($db_field = mysql_fetch_assoc($result)) {
$is_search = stristr($desc, $varsearch);
if($is_search !== FALSE) {
Echo " <P><FORM NAME=order ACTION=\"managecart.html\" onSubmit=\"AddToCart(this);\"> ";
Echo " <input type=\"image\" src=\"./images/acheter.gif\" border=0 value=\"Add to Cart\" align=top> ";
Echo " </FORM> ";
}
}
so basically here is makes a <form> for each item that make the stristr() different than false (this is fine)
It make no difference if ACTION=magementcart.html is in the <form> or not... so when it execute the
addtocart(this) and come back, it refresh the page with all the items in inventory.... this is what i dont like because the customer has to retype in the search field to continue their shopping.
thanks for your help