Forum Moderators: coopster

Message Too Old, No Replies

Simple Enquiry Script

Simple Enquiry Script

         

enderSFTD

4:04 am on Jan 12, 2009 (gmt 0)

10+ Year Member



Hi All,

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

cameraman

6:44 pm on Jan 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, enderSFTD.

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

enderSFTD

10:00 pm on Jan 12, 2009 (gmt 0)

10+ Year Member



cameraman!

You are my god you have been so helpfullllll!

Thanks heaps

enderSFTD

10:28 pm on Jan 12, 2009 (gmt 0)

10+ Year Member



just another quick question?

how would i add

$_SESSION['items'][] = '[*pagetitle*]';

to a button that does not direct away from the current page?
do i need php tags within the form?

cameraman

7:29 pm on Jan 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



php is only server-side - you wouldn't be able to do that in the form. About the only way would be to use javascript to send an ajax request to a php script on the server (you can find a number of ajax examples in the javascript forum).

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.