| 11:56 pm on May 30, 2007 (gmt 0)|
You can access the IP address using the $_GET array - $_GET[ip].
If you want to display it in a text box you can use this code:
echo '<input type="text" value="'.$_GET[ip].'">';
| 12:18 am on May 31, 2007 (gmt 0)|
This is not what I meant, sorry if my initial post wasn't clear.
I am using a form text box to type the ip in lets say the ip i am typing is 10.0.0.0
so i type 10.0.0.0 and press "Search" this search button submits to search.php, which I want to be able to list all the IPs 10.0.0.0 from a database.
the problem I have is that i list 20 records for 10.0.0.0 per page, when i click next to goto the next page it doesn't remember the $_POST['textbox'] item from the first page and returns no results because the search criteria originally from $_POST['textbox'] isnt set anymore.
I added an extra field to the URI called IP now i can access my results correctly but only by hand modfying the URI to be
i want to be able to do this automatically and not have to hand modify the URI so if i type 10.0.0.0 into the text box and press search it should make the initial URI include the value i typed in the text box.
Do you get me?
I dont have a clue how to do this properly so I am here seeking guidance.
any thoughts at all will be much appreciated
| 1:37 am on May 31, 2007 (gmt 0)|
I still don't quite understand how you're doing this. For moving on to the next lot of search results you can either set a hidden field with the IP address like this:
echo '<input type="hidden" name="ip" value="'.$_POST[ip].'">';
and then access the IP from the $_POST array on the next page, or add the IP address in the <form> code like this:
echo '<form action="search.php?ip='.$_POST[ip].'">';
and access the IP address from the $_GET array.
| 5:45 am on May 31, 2007 (gmt 0)|
// the next page it doesn't remember the $_POST['textbox'] item
Yea it is not supposed to. $_POST, $_REQUEST, $_GET, all get values of a form from just submitted forms, and you shouldn't expect them to be there by themselves in the following paes.
I would recommend you to assign them to a SESSION. May be put the id in the following manner:
$_SESSION['id'] = $_POST['textbox']; then use $_SESSION['id'] in the following pages.
or carry the values in hidden textboxes
<input type="hidden" value=". $_POST['textbox'] ." name = "textbox">
I hope this helps.
| 9:11 am on May 31, 2007 (gmt 0)|
will this work?
because when i click next, $_POST['textbox'] will not have been submitted to the next page so isnt it like saying
$_SESSION['ip'] = "/*nothing*/";
this is because when i click next to view the next page of results it loads the same file e.g.
search.php displays the first page of results based on the search criteria entered into the search box, on this initial search.php page i can click next if there are more than a certain number of results, my problem is that the search criteria isnt remembered because it reloads the search page which will store the $_POST['textbox'] value and sionce it reloads and theres nothing to post the value is empty when the page reloads.
since the $_POST['textbox'] field will be empty when i click next to view the next page of the search results.
so I thought that maybe I need to somehow get the value from $_POST['textbox'] into a $_GET value so that when i choose "next" on the first page of results it passes the search criteria onto the next page and so on and on....
I am not sure, any ideas?
PS- I was always throwing the idea of a session variale to store search criteria from the text box, not sure though thats why I am here .
[edited by: bysonary at 9:20 am (utc) on May 31, 2007]
| 9:19 am on May 31, 2007 (gmt 0)|
Once the SESSION values are set, you wouldn't need to change if that is what you are saying. You want keep on assign it to the POST. Assign the search text to the SESSION once, and keep on using the SESSION.
or use hidden text boxes, it is very widely used.
| 9:22 am on May 31, 2007 (gmt 0)|
Yes i know but if i press next the code to set the session variable is reset the the value of $_POST['textbox'] which will be empty?
could i place it like this?
| 1:52 pm on May 31, 2007 (gmt 0)|
|when i click next to goto the next page it doesn't remember... |
the link you click has a query string at the end. Just make that query string include the current query also (whatever you just searched for). like?page=1&query=10.0.0.0
| 6:07 pm on May 31, 2007 (gmt 0)|
I would avoid sessions and use either hidden inputs or writing the query string into hrefs.
Reason? The same user could have two browser windows open with different queries in each one. Whichever was opened last would overwrite the search query of the first window.
| 12:10 pm on Jun 2, 2007 (gmt 0)|
hey all your suggestions are great and I know how I could get it working in my theory but in practice its proving difficult.
here goes ill try explain once more
HOW do i get the value from the textbox, into the url header? I could use:
echo '<a href="search.php?ip='.$_POST['textbox'].'>Next</a>";
one problem there tho, when i click NEXT the form will be empty! so its like saying its nothing. Because each time next is pressed it reloads the same page only like this
you see what I mean now? when im on page 1, its fine yeah but on page 2 nothing was previously entered into the textbox so using $_POST['textbox'] would be wrong, or am i wrong?
any further advice here appreciated
ps - is it possible without session variables?