Solved

Get php to remeber a variable value

Posted on 2003-11-17
4
385 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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 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