Jump to content

Problem Storing Values as Session Variables


rbragg

Recommended Posts

I have a submit-type button named "done". I am doing print testing and initially, this is what is printed:

 

Request_Method = GET

Post Data: Array ( )

Sessions: Array ( )

 

If I enter some values and submit, they are populated into the Post array and not the Sessions array. I have maintained the values and when I submit again, it then populates the values into the Sessions array, however, nothing is able to be passed to the next page. Values are able to be passed to the next page via the Post method. I'm bewildered.

 

<?php 
session_start();

echo 'Request_Method = ' .$_SERVER['REQUEST_METHOD']; # print testing
echo "<br>\n" . 'Post Data: '; @print_r($_POST);
echo "<br>\n" . 'Sessions: '; @print_r($_SESSION);
echo "<br>\n"; 

if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['done']) ) # only if form is submitted
{
foreach ($_POST as $key => $value) # put the values into session variables
{
  if ($key != "done") # if user didn't reach this page by submitting
	{
		$_SESSION[$key] = strip_tags($value); # strip tags
	}
}
include 'lots_validate.php'; # and direct to validate
}
?>	

<form name="lots_choose" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

Link to comment
Share on other sites

I am not sure if we are just missing code, but I do not really see where the done part is set.

 

<input type="hidden" value="ok" name="done" />

 

Probably should be somewhere I hope. If not your data is never entering into that first if statement.

 

--FrosT

Link to comment
Share on other sites

Sure guys:

<?php 
session_start();

echo 'Request_Method = ' .$_SERVER['REQUEST_METHOD']; # print testing
echo "<br>\n" . 'Post Data: '; @print_r($_POST);
echo "<br>\n" . 'Sessions: '; @print_r($_SESSION);
echo "<br>\n"; 

if( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['done']) ) # only if form is submitted
{
foreach ($_POST as $key => $value) # put the values into session variables
{
  if ($key != "done") # if user didn't reach this page by submitting
	{
		$_SESSION[$key] = strip_tags($value); # strip tags
	}
}
include 'lots_validate.php'; # and direct to validate
}
?>	

<form name="lots_choose" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">

<div id="middle_title">Lots</div>
<div class="style1" align="right">sign out</div>	
<div align="center">	
<p class="style1">Please choose to open or close the following lots:</p>
<table width="25%" border="0" align="center" cellpadding="1" cellspacing="0">
  <tr>
	<td width="15%" class="style2"><u>Lot</u></td>
	<td width="5%" class="style2"><u>Open</u></td>
	<td width="5%" class="style2"><u>Close</u></td>
  </tr>

  <tr>
	<td class="style1">11</td>
	<td><label for="open11" class="style1">
	<?php
	$sticky11= ( (isset($_SESSION['rb11'])) && ($_SESSION['rb11'] == 'open') )?' checked="checked" ':' '; # maintains entry
	echo '<input type="radio" name="rb11" id="open11" value="open" ' . $sticky11 . '/> '; # displays radiobutton with maintained entry
	?>	
	</label></td>
	<td><label for="close11" class="style1">
	<?php
	$sticky11= ( (isset($_SESSION['rb11'])) && ($_SESSION['rb11'] == 'closed') )?' checked="checked" ':' '; # maintains entry
	echo '<input  type="radio" name="rb11" id="close11" value="closed" ' . $sticky11 . '/> '; # displays radiobutton with maintained entry
	?>
	</label></td>
  </tr>
          <tr>
    <td colspan="3" align="right"><input class="style1" type="submit" name="done" id="done" value="done"></td>
         </tr>

       </table>

</div>	
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.