jezella
asked on
variable $_SESSION in Form Submit
Hi all. Hope you can help a php learner.
I have created a form with 2 submit buttons so that a choice between registering or logging in is offered.
When the form is sent I wish to be able to change the value of $_SESSION['userType'] = 'guest' from guest to either registration request or loginRequest.
Help here would be appreciated where my code is below. I feel that this could be achieved onClick before the form is posted though perhaps this may be better.
<?php
session_start();
$sessionValue = $_POST['formsubmit'];
$_SESSION['userType'] = $sessionValue;
?>
Many thanks
Jezella
<?php
session_start();
$_SESSION['userType'] = 'guest';
?>
<br/><h2 align = "center">Welcome to the Ashley Site</h2> <h2 align = "center">You Must be a Logged in Member to Use
this Site</h2> <h3 align = "center">Select Login or Register<h3>
<table align = "center" border = "1" width = "250">
<form method = "post" action = "index.php">
<tr>
<td>Register</td>
<td>Login</td>
</tr>
<tr>
<td><input type = "submit" name = "formsubmit" value = "register" title = "Register"></td>
<td><input type = "submit" name = "formsubmit" value = "login" title = "Login"></td>
</tr>
</form>
</table>
I have created a form with 2 submit buttons so that a choice between registering or logging in is offered.
When the form is sent I wish to be able to change the value of $_SESSION['userType'] = 'guest' from guest to either registration request or loginRequest.
Help here would be appreciated where my code is below. I feel that this could be achieved onClick before the form is posted though perhaps this may be better.
<?php
session_start();
$sessionValue = $_POST['formsubmit'];
$_SESSION['userType'] = $sessionValue;
?>
Many thanks
Jezella
<?php
session_start();
$_SESSION['userType'] = 'guest';
?>
<br/><h2 align = "center">Welcome to the Ashley Site</h2> <h2 align = "center">You Must be a Logged in Member to Use
this Site</h2> <h3 align = "center">Select Login or Register<h3>
<table align = "center" border = "1" width = "250">
<form method = "post" action = "index.php">
<tr>
<td>Register</td>
<td>Login</td>
</tr>
<tr>
<td><input type = "submit" name = "formsubmit" value = "register" title = "Register"></td>
<td><input type = "submit" name = "formsubmit" value = "login" title = "Login"></td>
</tr>
</form>
</table>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<?php
session_start();
if(isset($_POST['formsubmi t]))
{
if( $_POST['formsubmit] == "register") $_SESSION['userType'] = 'register';
if( $_POST['formsubmit] == "login") $_SESSION['userType'] = 'login';
}else
{
$_SESSION['userType'] = 'guest';
}
?>
session_start();
if(isset($_POST['formsubmi
{
if( $_POST['formsubmit] == "register") $_SESSION['userType'] = 'register';
if( $_POST['formsubmit] == "login") $_SESSION['userType'] = 'login';
}else
{
$_SESSION['userType'] = 'guest';
}
?>
<?php
session_start();
if(isset($_POST['registers ubmit'])){
$_SESSION['userType'] = $_POST['registersubmit'];
header('location: register.php');
}
else if(isset($_POST['loginsubm it'])){
$_SESSION['userType'] = $_POST['loginsubmit'];
header('location: login.php');
}
else{
$_SESSION['userType'] = 'guest';
}
?>
<br/><h2 align = "center">Welcome to the Ashley Site</h2> <h2 align = "center">You Must be a Logged in Member to Use
this Site</h2> <h3 align = "center">Select Login or Register<h3>
<table align = "center" border = "1" width = "250">
<form method = "post" action = "index.php">
<tr>
<td>Register</td>
<td>Login</td>
</tr>
<tr>
<td><input type = "submit" name = "registersubmit" value = "register" title = "Register"></td>
<td><input type = "submit" name = "loginsubmit" value = "login" title = "Login"></td>
</tr>
</form>
</table>
session_start();
if(isset($_POST['registers
$_SESSION['userType'] = $_POST['registersubmit'];
header('location: register.php');
}
else if(isset($_POST['loginsubm
$_SESSION['userType'] = $_POST['loginsubmit'];
header('location: login.php');
}
else{
$_SESSION['userType'] = 'guest';
}
?>
<br/><h2 align = "center">Welcome to the Ashley Site</h2> <h2 align = "center">You Must be a Logged in Member to Use
this Site</h2> <h3 align = "center">Select Login or Register<h3>
<table align = "center" border = "1" width = "250">
<form method = "post" action = "index.php">
<tr>
<td>Register</td>
<td>Login</td>
</tr>
<tr>
<td><input type = "submit" name = "registersubmit" value = "register" title = "Register"></td>
<td><input type = "submit" name = "loginsubmit" value = "login" title = "Login"></td>
</tr>
</form>
</table>
ASKER
Thank you to all and sorry for the delay in my reply. I have read all the comments here and feel that all will achieve what I wanted to do. I think that the answer supplied by emplaticdigital may however be a shorter method.
Many thanks
Jezella.
Many thanks
Jezella.
session_start();
$_SESSION['userType'] = $_POST['formsubmit'];
?>