Forum Moderators: coopster

Message Too Old, No Replies

php session and checkboxes

         

HEki

8:27 am on Jun 19, 2008 (gmt 0)

10+ Year Member



Hi,

i want to achive this:
- page 1; has 2 items on it with checkboxes. Now i can select 1, 2, both or none.
- page 2; has 2 items also with checkboxes. Again i can select 1, 2, both or none.

On 3rd page i have an email form with the listed data selected on first 2 pages. when i fillout the form i send it to my email with the selected items.

Its like a simple shoppingcart thing.

Everyone told me to use session, but honestly, i dont know how to pull this off. now i have a contact form on both 2 pages and i have to fill out the form on both pages if i want to send the selected data to my email if i have selected something on the page ...

If anyone is willing to help me out with a simple example on how to store checkbox data in a session i will be more than grateful.

best regards,
heki

deMorte

11:12 am on Jun 19, 2008 (gmt 0)

10+ Year Member



This is a very basic example, but it should give you an idea on how to do it.
Page 1:
<form action="page2.php"> 
<input type="checkbox" name="item1">Item 1
<br>
<input type="checkbox" name="item2">Item 2
<br>
<input type="submit" value="send">
</form>

Page 2:
<?php 
session_start();
$_SESSION['item1'] = $_POST['item1'];
$_SESSION['item2'] = $_POST['item2'];
?>
<form action="page2.php">
<input type="checkbox" name="item3">Item 3
<br>
<input type="checkbox" name="item4">Item 4
<br>
<input type="submit" value="send">
</form>

Page 3:
<?php 
session_start();
$item1 = $_SESSION['item1'];
$item2 = $_SESSION['item2'];
$item3 = $_POST['item3'];
$item4 = $_POST['item4'];
?>

Now you should be able to use the $item variables to whatever you want.
This is not tested nor very good code, but should give you an idea on how to use session. You can find more info about sessions and how they work by googling.