co.ador Posted January 2, 2010 Share Posted January 2, 2010 I have a form sending in post action to page2.php How can I in page2.php receive those values and stored in a global variable $_SESSION to use it in a pagination script in page2.php? Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/ Share on other sites More sharing options...
mikesta707 Posted January 2, 2010 Share Posted January 2, 2010 session_start(); $_SESSION['whatever'] = $_POST['whatever']; ? Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/#findComment-987216 Share on other sites More sharing options...
co.ador Posted January 2, 2010 Author Share Posted January 2, 2010 Thank you mikesta your script will get the $_POST value and assign it to the $_SESSION variable. is the below correct? page2.php <?php $strZipCode = isset($_REQUEST['frmSearch']['zipcode'])?$_SESSION['zipcode']= mysql_real_escape_string($_REQUEST['frmSearch']['zipcode']):'';?> Above $strZipCode is equal to if isset then $_SESSION zipcode equal escaped $_REQUEST from the form zipcode? hope that set up is correct thank you mikesta. Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/#findComment-987237 Share on other sites More sharing options...
ignace Posted January 2, 2010 Share Posted January 2, 2010 Stop using the Hungarian Notation it doesn't work in a dynamic language and is misleading Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/#findComment-987238 Share on other sites More sharing options...
co.ador Posted January 2, 2010 Author Share Posted January 2, 2010 Thank for the suggestion on stopping using the Hungarian approach, but what about the question I have asked? do you have any comments? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/#findComment-987255 Share on other sites More sharing options...
teamatomic Posted January 3, 2010 Share Posted January 3, 2010 No. $_REQUEST['name'] is the same as $_POST['name'] or $_GET['name']. The name you assign to the form has nothing to do with it unless you are playing with JS,etc. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/#findComment-987414 Share on other sites More sharing options...
laffin Posted January 3, 2010 Share Posted January 3, 2010 1) You should not use $_REQUEST, as this can take values from $_POST/$_GET/$_COOKIE, if you use a form, use the proper $_POST. Using $_REQUEST just invites trouble 2) You never check the session value so a empty string is taken, if no $_POST is sent $strZipCode = isset($_POST['frmSearch']['zipcode'])?$_SESSION['zipcode']= mysql_real_escape_string($_POST['frmSearch']['zipcode']):(isset($_SESSION['zipcode'])?$_SESSION['zipcode']:''); check the POST, check the SESSION, otherwise, leave as '' Quote Link to comment https://forums.phpfreaks.com/topic/186946-help-on-building-a-session/#findComment-987415 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.