Solved

Get php to remeber a variable value

Posted on 2003-11-17
4
386 Views
Last Modified: 2013-12-13
How do I get PHP to remember a variable value when submitting a form the second (0r third)
time round?
0
Comment
Question by:AntonBotes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 2

Expert Comment

by:neele
ID: 9768297
You can use session object to store those values.

Storing value to session.
session_start();
$_SESSION['user_id'] = $userid; //storing the $userid value to session
$_SESSION['UserName'] = $username; //storing the $username value to session

To retrieve (sample ONLY)
====================
session_start();
if($_SESSION['user_id']) //check first in case..
$ID = $_SESSION['user_id']) //set it to variable $ID



0
 

Author Comment

by:AntonBotes
ID: 9770041
Comment on 'neele':

If I use 'session_start()' , it complains about '....cookie already sent...' and '..cache limit already sent'...'
If I don't use 'session_start()', it complains about '...undefined variable _SESSION...'.
0
 
LVL 2

Accepted Solution

by:
neele earned 50 total points
ID: 9771024
check in your php.ini :
session.auto_start = 1 //set to 1 so it auto-start the session.
session.save_path = C:\php\sessiondata //set the path for storing the session..data
session.use_trans_sid = 1

Try checking the setting..n see whether it works..

AND do place session_start(); at the very beginning of your code. If u r having other code..
in between..

e.g.
<?php
session_start();
....
....

?>


hope it helps
0
 
LVL 2

Expert Comment

by:neele
ID: 9771046
n Share this site with U. I think is quite a good reference :)

http://www.sitepoint.com/article/319/4
on php session
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question