setting $_SESSION variables
Moderator: General Moderators
setting $_SESSION variables
I am trying to start a session and to set each individual $_POST variable if it has been entered by the user of the form.
the first few lines of my php script code is as follows:
<?php
session_start() ;
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
Will this achieve it's aim? It does not appear to be working at the moment.
I then check each variable from the within the form using:
<input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){
echo $_SESSION['Name']; }?>" size="29">
Will this check the variable correctly?
the first few lines of my php script code is as follows:
<?php
session_start() ;
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
Will this achieve it's aim? It does not appear to be working at the moment.
I then check each variable from the within the form using:
<input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){
echo $_SESSION['Name']; }?>" size="29">
Will this check the variable correctly?
It looks good to me. Are you getting any error messages?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
2 things. My code uses the value attribute rather than the id tag, as follows:
I am not gettiing an error message. however, if I enter my name in the name field in the form, that field is blank after pressing the submit button.
Code: Select all
<input name="Name" type="text" [b]value[/b]="<?php if(isset($_SESSION['Name'])){
echo $_SESSION['Name']; }?>" tabindex="2" size="29">hey
then var_dump($_SESSION) after session_start() and see what you got there...
why don't you var_dump($_POST) and check that what you get is exepctedI then check each variable from the within the form using:
<input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){
echo $_SESSION['Name']; }?>" size="29">
then var_dump($_SESSION) after session_start() and see what you got there...
I do the following after starting the session:
which returns NULL. Can you see why this is returning a NULL?
Code: Select all
if(isset($_POST['submit'])){
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
}
var_dump($_SESSION['Name']);When I do a var_dump on $_SESSION, I get
array(0) { }
Therefore, $_SESSION has not been set for some reason. Any ideas why?
Again, the code I use to set it is as follows:
array(0) { }
Therefore, $_SESSION has not been set for some reason. Any ideas why?
Again, the code I use to set it is as follows:
Code: Select all
<?php
session_name('myForm');
session_start();
//phpinfo();
if(isset($_POST['submit'])){
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
}
var_dump($_POST);
var_dump($_SESSION);i doubt this will make any difference, but try
$_SESSION["$key"] = $val <-- using the double quotes
$_SESSION["$key"] = $val <-- using the double quotes
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Good man. It was not getting inside the loop at all.
I have sorted that out and now the $_SESSION['Name'] is set in this script.
However, this is still not being read in my form. The code is as follows:
Any suggestions?
I have sorted that out and now the $_SESSION['Name'] is set in this script.
However, this is still not being read in my form. The code is as follows:
Code: Select all
<input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){
echo $_SESSION['Name']; }?>" size="29">My form code is:
Is this what you mean?
My script code is:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="ExpressionInterest" method="post" action="sendmail.php">
<blockquote>
<p align="center"><img src="Formtitle.jpg" width="852" height="286" align="middle"></p>
<p align="center"><strong>REGISTER YOUR INTEREST </strong></p>
<p align="center">If you would like to register your interest in attending this event, please complete and </p>
<p align="center">return this form via fax to Norrie Keane at the following number: +353 (0)93 43887. </p>
<p align="center"><strong>Title </strong>:
<select name="Title" size="1" tabindex="1" dir="ltr">
<option> </option>
<option>Dr.</option>
<option>Mr.</option>
<option>Mrs.</option>
<option>Miss.</option>
</select>
<strong> Name </strong>:<strong>
<input name="Name" type="text" value="<?php if(isset($_SESSION['Name'])){
echo $_SESSION['Name']; }?>" tabindex="2" size="29">
</strong> <strong>Middle Initial </strong>:
<input name="Initial" type="text" id="Initial" tabindex="3" size="5" maxlength="4">
</p>
</blockquote>
<p align="center"><strong>Surname </strong>:
<input name="Surname" type="text" id="Surname" tabindex="4" size="67">
</p>
<blockquote>
<p align="center"><strong>Position </strong>:
<input name="Position" type="text" id="Position" tabindex="5" size="67">
</p>
<p align="center"><strong> Company </strong>:
<input name="Company" type="text" id="Company" tabindex="6" size="67">
</p>
<p align="center"><strong>Address </strong>:
<input name="Address1" type="text" tabindex="7" size="67">
</p>
<p align="center">
<input name="Address2" type="text" tabindex="8" size="67">
</p>
</blockquote>
<blockquote>
<div align="center"></div>
<div align="center">
<input name="Address3" type="text" tabindex="9" dir="ltr" size="67">
</div>
</blockquote>
<p align="center"> <strong>Country </strong>:
<input name="Country" type="text" tabindex="10" size="67">
</p>
<p align="center"><strong> Contact No </strong>:
<input name="ContactNumber" type="text" tabindex="11" size="67">
</p>
<p align="center">(Please include country code)
</p>
<p align="center"><strong>Cell Phone </strong>:
<input name="CellNumber" type="text" tabindex="12" size="67">
</p>
<p align="center">(Please include country code)
</p>
<p align="center"><strong>Email </strong>:
<input name="Email" type="text" tabindex="13" size="67">
</p>
<p align="center"> </p>
<p align="center">By completing this form, you will receive regular, updated Forum information, via email, </p>
<p align="center">as it becomes available, and an official invitation and information pack will be forwarded </p>
<p align="center"> to you via post in due course. </p>
<p align="center">
<input name="Submit" type="submit" tabindex="14" value="Submit">
<input name="Reset" type="reset" tabindex="15" value="Reset">
</p>
</form>
<p align="center">___________________________________________________________________________________ </p>
<p align="center">Moyne Park, Tuam, Co. Galway, Ireland </p>
<p align="center">Telephone: +353 (0)93 43900 Facsimile: +353 (0)93 43887 Email: nkeane@rivada.com </p>
<p> </p>
</body>
</html>My script code is:
Code: Select all
<?php
session_name('myForm');
session_start();
//phpinfo();
if(isset($_POST['Submit'])){
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
}
//var_dump($_POST);
//var_dump($_SESSION['Name']);
$email = $_POST['Email'];
$body = $_POST['Title']."\n";
$body .= $_POST['Name']."\n";
$body .= $_POST['Initial']."\n";
$body .= $_POST['Surname']."\n";
$body .= $_POST['Position']."\n";
$body .= $_POST['Company']."\n";
$body .= $_POST['Address1']."\n";
$body .= $_POST['Address2']."\n";
$body .= $_POST['Address3']."\n";
$body .= $_POST['Country']."\n";
$body .= $_POST['ContactNumber']."\n";
$body .= $_POST['CellNumber']."\n";
$body .= $_POST['Email']."\n";
mail( "albert_oflaherty@hotmail.com", "Expression Of Interest in Forum on Public Safety 2006", $body, "From: $email" );
header( "Location: http://www.bertsparadise.com/ExpressionOfInterest3.php" );
?>