Solved

PHP Sessions

Posted on 2009-07-04
1
207 Views
Last Modified: 2012-05-07
Hi all I need to record into a session a value passed by a form to the same page. It' like this I need to fill a form and call the same page recording all the values in a session. How should I go about it?
Thanks.
0
Comment
Question by:doRodrigo
1 Comment
 
LVL 5

Accepted Solution

by:
yauhing earned 500 total points
ID: 24778696
Please try below example:

If value "name" was found in the $_POST, it will be added to the session.
<?php
session_start(); // start the session
 
if(isset($_POST['name'])){
	// if the name post from previous page, set it to the session
	$_SESSION['name'] = $_POST['name'];
}
?>
<pre>
Existing Session:
<?php 
	// print out the session value
	print_r($_SESSION); 
?>
</pre>
 
Input form for test:<br>
<form method="post">
Name: <input type="text" name="name" value="Test Name">
<input type="submit">
</form>

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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