Jump to content

Archived

This topic is now archived and is closed to further replies.

jwk811

Sessions, need code

Recommended Posts

How will I get data using php when I user clicks on a button? I want it so when someone clicks add to cart the item will go to another (their cart) and so will they to check it. I need that data to stay there even when they go to another page and some back. If someone could give me more detailed information that would be great but right now I'm just trying to get this one part down.

Share this post


Link to post
Share on other sites
Hey,

Put this on the top of the page:

$_SESSION['cart']['first_name'] = $_POST['first_name']

Just like that! Hope this helps! :)

Share this post


Link to post
Share on other sites
do i put one of those for every item? instead of having full_name put the item and make a new line for each other item? then when they click the button they will go to there cart and i can... wait im stuck how will i get that item there.

Share this post


Link to post
Share on other sites
You might also need to call session_start() at the top of your page too (before ANY html at all, even blank lines.  If you have trouble, check the thread on header errors).

You might not need to call it, it depends on your php configuration.

Once sessions are active (triggered by session_start()), then any data you place into the $_SESSION[] array will be available between requests.

Share this post


Link to post
Share on other sites
How will I get that data to the other page? If I have session_start at the top. Then where my button is that says add to cart how will I be able to add that item to the cart? $_SESSION[]... what do i put between the brackets and how to make the info send? Do I add that in the form somehow?

Share this post


Link to post
Share on other sites
I know that, this was my message.

[quote]How will I get that data to the other page? If I have session_start at the top. Then where my button is that says add to cart how will I be able to add that item to the cart? $_SESSION[]... what do i put between the brackets and how to make the info send? Do I add that in the form somehow?[/quote]

Now how am I going to get this to work?

Share this post


Link to post
Share on other sites
@jwk811

like this:

session_start();
$_SESSION['cart']['first_name'] = $_POST['first_name'];

//FORM
<input name="first_name" value="Yes" type="textfield" value="<?php echo $_SESSION['cart']['first_name'] ?>">

Hope you do get it!
Goodluck dude!

Share this post


Link to post
Share on other sites
put ob_start(); after session_start(); and put ob_end_flush(); at before ?> tag... it will help to block the php session warnings... if you have any doubt about it then ask me here...

Share this post


Link to post
Share on other sites
you relly should never use ob_start if there is an error then solve it.

in my option ob_start(); is a tempary method and  a lazy solution.

sorry.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.