Forum Moderators: coopster
Just a quick bit of help.
I have a website that rents out appliances i.e fridges, tvs, kettles
at the moment to enquire customers go to the enquiry form page and
tick the things they are interesed in i.e kettles and TV's
and send me an email.
What i have been trying to do is start a php session and have
a button on each of the product pages that says add to cart...
for example they go to the Television page and click ad to enquiry
then they go to the kettle page and click add to enquiry...
then when they are done theres another button Submit Enquiry which sends them to the form which already knows what they want and they just fill out their details.
Its very simple but im really useless i understand the basics of php
but i do not know how to append to a session variable.
I dont have any code yet just been trying to hack some simple carts for my uses but i just cant do it
If anyone could help me out that would be amazing... thanks all
Sessions are pretty easy because php does all the work in the background.
At or near the top of each script that you want to be able to store or retrieve session variables, place this line:
session_start [us3.php.net]();
Then to store a value it's as easy as:
$_SESSION['variable_name'] = 'some value';
$_SESSION['other_variable'] = 36;
To retrieve:
echo $_SESSION['variable_name'];
In your case you'll probably be interested in saving an array of values, for example the script that processes the form post on the tv product page:
$_SESSION['items'][] = 'tv';
and kettles:
$_SESSION['items'][] = 'kettle';
Then to see them:
print_r($_SESSION['items']);
to go through them one by one:
foreach($_SESSION['items'] as $item) {
echo "I see you would like to rent our " . $item;
} // EndForEach item added
The form's action could be the same page, though, so if the button is on, say, fridge.php, the form's action would be fridge.php. When the form is submitted you set the session value and redisplay fridge's content.