Jump to content


Photo

Sessions, need code


  • Please log in to reply
10 replies to this topic

#1 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 06 September 2006 - 12:54 AM

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.

#2 mitzleah

mitzleah
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationManila, Philippines

Posted 06 September 2006 - 01:20 AM

Hey,

Put this on the top of the page:

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

Just like that! Hope this helps! :)

#3 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 06 September 2006 - 01:27 AM

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.

#4 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 06 September 2006 - 01:29 AM

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.

#5 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 06 September 2006 - 01:32 AM

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?

#6 mitzleah

mitzleah
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationManila, Philippines

Posted 06 September 2006 - 01:35 AM

btherl  is right you must first call session_start().  ;D

#7 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 06 September 2006 - 01:36 AM

I know that, this was my message.

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?


Now how am I going to get this to work?

#8 mitzleah

mitzleah
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationManila, Philippines

Posted 06 September 2006 - 01:44 AM

@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!


#9 jwk811

jwk811
  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 06 September 2006 - 01:49 AM

okay i think thats what i needed.. thank you :D

#10 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 06 September 2006 - 09:05 AM

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...
www.karthi.us

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 06 September 2006 - 11:02 AM

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.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users