Forum Moderators: coopster

Message Too Old, No Replies

posting multiple items on different pages to form

is this possible?

         

bessington

7:31 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



Hello there.. I am a bit new to PHP but am trying to create a "cart-like" php script.. not that many products on the site so am not going to use MYSQL (and i can't based on the project specs) - is it possible to have multiple products on multiple pages and when clicked to purchase, the values of these products all get sent to a single page (all the products the customer wants to get ordered will be sent as a request via e-mail when they checkout)?

Is there a way to do this? I know I can sort the values like this (this might be somewhat incorrect):

$stop=1;
for($num=1; $stop!=""; $num++) {
$varname1="Name$num";
$varname2="Price$num";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"Name$num\" value=\"${$varname1}\">";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"Price$num\" value=\"${$varname2}\">";
echo " varname1 = ${$varname1} <br>" ;
echo " varname2 = ${$varname2} <br>" ;
$stop = ${$varname1};
}

Basically, How can I have multiple product variables selected by the customer and then sorted and printed out on an order form.

My logic may be a bit off on this - I greatly appreciate any help.

-Bess

breezeman

7:37 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



I would store the selected items on each page in a session variable and on the checkout page you can use these session variables to create your order form.

bessington

8:00 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



thanks for your help! I am not sure of the exact code to have the session variables stored and then printed out..

would it be something like this for each page with a product on it:

session_start();
$_SESSION['productname' = 'Name of Product on this page';
$_SESSION['productprice' = 'Price of Product on this page';

and then on the form:

session_start();
print '<p> You have selected, ' . ($_SESSION['productname']) . </p>';

Would I use to use a seperate variable for every product to have them all printed out? Such as $_SESSION['productname1', each a unique session id on the product pages? thank you!

-bess

breezeman

9:29 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



The session_start() should be at the top of every page.

On a form submit store the selected form checkboxes in variables:

if (isset($submit)){
//form is submitted

if (isset($_POST[product1)) {$_SESSION['product1])=$_POST['product1'];
$_SESSION['priceproduct1])=$_POST['priceproduct1'];}
if (isset($_POST[product2)) {$_SESSION['product2])=$_POST['product2'];$_SESSION['priceproduct2])=$_POST['priceproduct2'];}
}

ect.

Perhaps there is a faster way to do this with an array, I am not sure.

And on the checkout page somthing like
if (isset($_SESSION['product1']) {echo 'you ordered '.$_SESSION['product1'];}

bessington

10:20 pm on Jun 30, 2005 (gmt 0)

10+ Year Member



thanks so much - I will try this out.

Does anyone else have any advice for being able to set up these results in an array? Thank you!