PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Sun Mar 28, 2004 2:21 pm
The following is my code to use a form field to insert a value into to Session variable. However, I can't get the session variable to be updated when the form action is made. Yes I am a newbie!
Code: Select all
<?php
session_start();
session_register('session_var');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Testing Sessions page 1</title>
</head>
<body>
<?php
if($form_var) {
$session_var = $form_var;
}
?>
<form action="sessionTest2.php" method="post">
<input name="form_var" type="text" value="testing">
<input name="" type="submit" value="Go to Next Page">
</form>
</body>
</html>
ody
Forum Contributor
Posts: 147 Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK
Post
by ody » Sun Mar 28, 2004 2:31 pm
have you got register_globals set to off? If so you need to use the super globals $_SESSION and $_POST to access the varibles:
<?php
if(isset($_POST[form_var])) {
$_SESSION[session_var]= $_POST[form_var];
echo $_SESSION[session_var];
}
?>
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Sun Mar 28, 2004 3:16 pm
Tried the code you suggested and it didn't work either. Can't understand what is going to on.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sun Mar 28, 2004 3:20 pm
In sessionTest2.php you'll need ..
session_start();
if(!empty($_POST['form_var'])){
$_SESSION['form_var'] = $_POST['form_var'];
}
theoph
Forum Commoner
Posts: 47 Joined: Wed Jul 30, 2003 5:26 pm
Location: Lexington, KY USA
Post
by theoph » Sun Mar 28, 2004 10:15 pm
Thanks it work!