By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,089 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,089 IT Pros & Developers. It's quick & easy.

Sessions not getting updated

P: n/a
Hi,

I posted on this matter earlier with the subject line "Trouble with
sessions," but someone else started a different thread with the same
subject line that arrived before my post, so I'm changing my subject
line in order to avoid confusion.

I was asked to provide a code example for analysis, so here it is,
along with a
a description of what the problem is.

I'm working with sessions and the values for HTML text fields
(input="text") aren't getting updated after the first time I submit
the form. If I shut down my browser and start anew, I can write to the
session just once, as before. On the other hand, radio buttons -- used
with the Sticky Multivalued Parameters script on pages 170-171 of
O'Reilly's "Programming PHP" -- are updated every time. Here's an
example of my code. Many thanks to anyone who can make sense of what's
going on here.

Best wishes,

Mountain Man
<html>
<head>
<title>First Form Sessions</title>
</head>
<body>
<form action="form_processor.php4" method="POST">
First Name: <input type="text" name="firstName" value="<?php echo
$firstName ?>" /><br />
<input type="submit" />
</form>

</body>
</html>

// Next, the form processing script which is on another page.
// In my more complex script of actual use the form is only
// included if it doesn't pass validation.

<?php
session_start();
session_register("firstName");
?>

<html>
<head>
<title>Form Processor Sessions</title>
</head>
<body>

<?php
echo "$firstName<br />";
include 'first_form.php4';
?>

</body>
</html>
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Mountain Man wrote:
I'm working with sessions and the values for HTML text fields
(input="text") aren't getting updated after the first time I submit
the form. If I shut down my browser and start anew, I can write to the
session just once, as before. On the other hand, radio buttons -- used
with the Sticky Multivalued Parameters script on pages 170-171 of
O'Reilly's "Programming PHP" -- are updated every time. Here's an
example of my code. Many thanks to anyone who can make sense of what's
going on here.


Using php version >= 4.1? Then start using the $_SESSION superglobal:

<?

// Enable sessions
session_start();

// Get the page URL
$page = $_SERVER['PHP_SELF'];

// Destroy the session var
if (isset($_GET['unset'])) {
if (isset($_SESSION['test'])) {
unset($_SESSION['test']);
header("Location: $page");
exit;
}
}

// Update/create the session var
if (isset($_SESSION['test'])) {
$_SESSION['test']++;
} else {
$_SESSION['test'] = 1;
}

// Debug output
print "test = {$_SESSION['test']}<br />";
print "<a href='$page?unset=1'>Destroy session</a>";

?>
JW

Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.