Valentina Posted September 10, 2008 Share Posted September 10, 2008 Hello, I believe this question was probably answered to death, and I looked for old posts, but I couldn't find anything to solve my problem... Could somebody please help me? I wrote a search script that needs pagination. The script uses the _POST method to deal with the variables in the form. Being a beginner, it took me a while to realize that _POST does not carry the variables to the next page, but I cannot use _GET - there are too many variables that need to be passed to the next page. I tried SESSION also, but I either don't use it right, or it's simply not working... I cannot tell. What would be the best way to deal with this problem? I can post parts of the script if you need me to, I just am not sure what exactly would be needed... Thank you so much for your help! Valentina Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/ Share on other sites More sharing options...
lisa71283 Posted September 10, 2008 Share Posted September 10, 2008 Why not create a SQL table keyed by the SESSSIONID that contains the necessary information? Each hit would load the information as required. Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638053 Share on other sites More sharing options...
vicodin Posted September 10, 2008 Share Posted September 10, 2008 Not really sure what your asking for, can you please clarify. By the way when using session. You need session_start() at the beginning of each page you want to be part of the session. your variables get stored like this $_SESSION['Your-Variable-Name-Here'] Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638054 Share on other sites More sharing options...
Valentina Posted September 10, 2008 Author Share Posted September 10, 2008 Lisa, I have no idea how to do that. If you could offer some code to help me, I would appreciate it very much. vicodin, I am trying to create links for pages. I want to query the MySql database, get a bunch of results and display only 10 per page. I have no problem doing all these using GET, but it's not working with POST. I need to use POST. This is my code when trying with SESSION: <?php session_start(); ?> <html> <head> ...... stuff here, form....... if (!isset($_SESSION['hybridizer']) || !isset($_SESSION['seedparent']) || !isset($_SESSION['color[]']) || !isset($_SESSION['flowerform[]']) || !isset($_SESSION['orgcountry']) || !isset($_SESSION['year'])) { $_SESSION['hybridizer']=$_POST['hybridizer']; $_SESSION['seedparent']=$_POST['seedparent']; $_SESSION['color[]']=$_POST['color[]']; $_SESSION['flowerform[]']=$_POST['flowerform[]']; $_SESSION['orgcountry']=$_POST['orgcountry']; $_SESSION['year']=$_POST['year']; } $hybridizer = htmlentities($_SESSION['hybridizer']); $cleanhybridizer = trim($hybridizer); $seedparent = htmlentities($_SESSION['seedparent']); $cleanseedparent = trim($seedparent); $color = $_SESSION['color[]']; $color_1 = $color[0]; $color_2 = $color[1]; $color_3 = $color[2]; $color_4 = $color[3]; $color_5 = $color[4]; $color_6 = $color[5]; $color_7 = $color[6]; $color_8 = $color[7]; $color_9 = $color[8]; $flowerform = $_SESSION['flowerform[]']; $flowerform_1 = $flowerform[0]; $flowerform_2 = $flowerform[1]; $flowerform_3 = $flowerform[2]; $orgcountry = htmlentities($_SESSION['orgcountry']); $cleanorgcountry = trim($orgcountry); $year = htmlentities($_SESSION['year']); $cleanyear = trim($year); ........ then all the script stuff..... Am I doing something wrong here? How exactly am I supposed to write the links to the next page? Would it be something similar to writing them for GET, but just use SESSION[] instead? Or there is no need to write everything in the link anymore... I am really not sure what I'm doing... I appreciate your help! Valentina Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638068 Share on other sites More sharing options...
vicodin Posted September 10, 2008 Share Posted September 10, 2008 Post works the same way as get. It just doesnt go in the URL and is only passed to the next page. After the next page its gone. So intead of $_GET['Your-Var'] use $_POST['Your-Var'] and make sure in your form you change the method to post. Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638071 Share on other sites More sharing options...
Valentina Posted September 10, 2008 Author Share Posted September 10, 2008 vicodin, I am not sure I understand what you're saying.... I tried using POST like this: $hybridizer = htmlentities($_POST['hybridizer']); $cleanhybridizer = trim($hybridizer); $seedparent = htmlentities($_POST['seedparent']); $cleanseedparent = trim($seedparent); $color = $_POST["color"]; $color_1 = $color[0]; $color_2 = $color[1]; $color_3 = $color[2]; $color_4 = $color[3]; $color_5 = $color[4]; $color_6 = $color[5]; $color_7 = $color[6]; $color_8 = $color[7]; $color_9 = $color[8]; $flowerform = $_POST["flowerform"]; $flowerform_1 = $flowerform[0]; $flowerform_2 = $flowerform[1]; $flowerform_3 = $flowerform[2]; $orgcountry = htmlentities($_POST['orgcountry']) ; $cleanorgcountry = trim($orgcountry); $year = htmlentities($_POST['year']) ; $cleanyear = trim($year); And then later, for pages, I have this: echo "<a href='{$_SERVER['PHP_SELF']}?page_number=$next&hybridizer=$hybridizer&seedparent=$seedparent&color[] .......... all the rest of them ........ </a> When you click on the next page, there are no variables. They are lost. I tried doing all these using GET in the form. It works, but it doesn't carry all the variables. Valentina Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638075 Share on other sites More sharing options...
vicodin Posted September 10, 2008 Share Posted September 10, 2008 Post can only be used in a form... sorry forgot about that... if your gonna pass variables like that then they ether need to go in the db or you need to use a session... thats the only way. Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638076 Share on other sites More sharing options...
Valentina Posted September 10, 2008 Author Share Posted September 10, 2008 Well, these variables are coming from a form that uses method POST. As I said, I tried SESSION (I posted the code earlier) but I am not sure if I'm doing something wrong and I have no idea what I'm supposed to do next with those variables, to pass them to the next page. Valentina Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638077 Share on other sites More sharing options...
vicodin Posted September 10, 2008 Share Posted September 10, 2008 Post your form please... As long as the very first thing on the page is <?php session_start(); ?> And you are using it like this: <?php $flowerform = $_SESSION['flowerform']; ?> Then there is no reason for it not to work besides sessions being turned off in you php.ini ... Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638084 Share on other sites More sharing options...
Valentina Posted September 10, 2008 Author Share Posted September 10, 2008 Well, I discovered what I was doing wrong... I wasn't registering the arrays in the form. I was writing the code wrong. Anyway, I got that fixed, but this SESSION method doesn't work for what my script is trying to do... My form has multiple search options... lots of checkboxes and text boxes... When I use SESSION, it works to do a search for the first time (I don't even know if the pagination works) but if I want to do another search, choosing different boxes to check, the script obviously remembers the first choices too. I am not sure what I should do.... Valentina Link to comment https://forums.phpfreaks.com/topic/123547-pagination-with-_post-could-you-please-help/#findComment-638202 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.