aebstract Posted February 1, 2008 Share Posted February 1, 2008 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.. Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/ Share on other sites More sharing options...
kenrbnsn Posted February 1, 2008 Share Posted February 1, 2008 Do you have <?php sesssion_start(); ?> at the start of the script(s)? Ken Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/#findComment-455462 Share on other sites More sharing options...
duclet Posted February 1, 2008 Share Posted February 1, 2008 Also remember that you must have not outputted anything, even a space, in order for sessions to be set. But from looking at your code, I say that kenrbnsn is right, you probably forgot to start the session. Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/#findComment-455465 Share on other sites More sharing options...
avo Posted February 1, 2008 Share Posted February 1, 2008 Hi Are you reading an old session that did have a value stored .This will remain set if you have not unset it and can cause confusion. Regards. Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/#findComment-455476 Share on other sites More sharing options...
aebstract Posted February 1, 2008 Author Share Posted February 1, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/#findComment-455511 Share on other sites More sharing options...
aebstract Posted February 1, 2008 Author Share Posted February 1, 2008 I could post my entire page, but I am 99% sure it would confuse people since I have been working on these scripts myself and have a good working order for myself. Not so much for anyone else to find anything, let me know if you want that though! Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/#findComment-455519 Share on other sites More sharing options...
aebstract Posted February 1, 2008 Author Share Posted February 1, 2008 Quote Link to comment https://forums.phpfreaks.com/topic/88918-sessions-setting-wrong-information/#findComment-455573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.