Jump to content

sessions setting wrong information


aebstract

Recommended Posts

I have a page that allows the user to change their saved default address. Basically by setting sessions for each part of the address and another session that tells me if they have changed it or not. When I go and check if it is set, I'm getting a positive response back telling me that it either is or isn't set, though my sessions are displaying my normal address information.

 

if (isset ($_POST['submit']))
{

$problem = FALSE;


      if (empty ($_POST['street'])) {
$problem = TRUE;
$error .= 'Street is a required field. <br />';
      }

      if (empty ($_POST['city'])) {
$problem = TRUE;
$error .= 'City is a required field. <br />';
      }

      if (empty ($_POST['state'])) {
$problem = TRUE;
$error .= 'State is a required field. <br />';
      }

      if (empty ($_POST['zip'])) {
$problem = TRUE;
$error .= 'Zip is a required field. <br />';
      }





if (!$problem) {

$_SESSION['city'] = ucwords($_POST['city']);
$_SESSION['state'] = strtoupper($_POST['state']);

$_SESSION['zip'] = $_POST['zip'];
$_SESSION['street'] = $_POST['street'];
$_SESSION['tempaddress'] = 1;

                      header("Location: index.php?page=checkout");


}

}




$content .= "
<p><u><a href=\"index.php?page=accounthome\">$plantloc</a></u> - Alternate Address </p>

<form action=\"index.php?page=checkout&alternate=change\" method=\"post\">
Street:<br />
<input type=\"text\" size=\"20\" name=\"street\" value=\"$_POST[street]\" /><br /><br />
<table><tr><td>
City:
</td><td>
State:
</td><td>
Zip:
</td></tr>
<tr><td>
<input type=\"text\" size=\"10\" name=\"city\" value=\"$_POST[city]\" />
</td><td>
<input type=\"text\" size=\"2\" name=\"state\" value=\"$_POST[state]\" />
</td><td>
<input type=\"text\" size=\"5\" name=\"zip\" value=\"$_POST[zip]\" />
</td></tr></table>
<br />
<input type=\"submit\" name=\"submit\" class=\"textfield\" value=\"Submit Address\" />
</form>
";




} else {

This is the code that I use to set the session variables (the form and processing code)

 

 

This is where I am taking it and setting my current address (be it the regular or temporary changed one)

if ($_SESSION['tempaddress'] == 1){
$displayaddress = "
$_SESSION[street]<br />
$_SESSION[city], $_SESSION[state] $_SESSION[zip]<br />
";
}


if ($_SESSION['tempaddress'] == 1) {
$address2 = $displayaddress;
} else {
$address2 = $address;
}

 

 

$address2 displays the stored database information regardless of if I set the session or not..

Link to comment
https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/
Share on other sites

well.. like I said, the $_SESSION[tempaddress] IS setting to 1 when I submit the form, and I have a reset button that changes it back to a 0, and everytime I fill out the change address form, it sets it to 1. So the sessions ARE getting set. The session start IS at the top of the page.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.