homepage Welcome to WebmasterWorld Guest from 54.198.42.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
php $ GET from a form
bysonary




msg:3353938
 10:09 pm on May 30, 2007 (gmt 0)

Hello.

I am working on a system that logs IP addresses, I posted earlier about pagination, which I now have sorted however I am now attempting to implement a search feature that will display the results and also offer the pagination.

The paghination is working like this

mysite.com/logs.php?limit=10&page=1

I have introduced a new file called search.php that has the following URI, mysite.com/search.php?ip=192.168.0.1&limit=10&page=1

my problem is getting the IP address or value typed into the search text box (the search text box appears at the top of the search.php file), How do i get the value from the search text box into the URI, and also how do i make it so that once it is in a variable that variable will never change, even if the page is reloaded (session variables?) so I suppose its more of how do i get the search text into a session variable, and then get the session variable into the URI for the ip attribute?

any help here would be appreciated, if you need to see code snippets just ask, I didn't want to post the entire code as its long and also incase the solution didn't need it.

anyhow any help appreciated as i mentioned before.

TIA

ChrisW

 

barns101




msg:3354014
 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].'">';

bysonary




msg:3354022
 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

mysite.com/search.php?ip=10.0.0.0

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

Thanks again

ChrisW

barns101




msg:3354063
 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.

Habtom




msg:3354210
 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.

Habtom

bysonary




msg:3354356
 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?

thanks again

ChrisW

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]

Habtom




msg:3354360
 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.

Habtom

bysonary




msg:3354361
 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?

if(isset($_SESSION['ip'])
{
//do code
}

slade7




msg:3354565
 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

whoisgregg




msg:3354882
 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.

bysonary




msg:3356627
 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

search.php?ip=?&page=2

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?

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved