Link to home
Start Free TrialLog in
Avatar of CaptWill
CaptWill

asked on

Forcing a post or get within a URL

If I have a form within a webpage that contains a field, can I force my data to display the desired search results just by passing the field variable with the url? The function that displays the result is called "showList".

For example:

http://www.mydomain.com/index.php?query=showList&field=NY

This brings up the page with the field prefilled in the box but does not currently initiate the search- I must click on the search button which then posts the form.
Avatar of gamebits
gamebits
Flag of Canada image

You pass the variable to a script that do the search and display the result

$field = $_GET['field'];

$result = mysql_query("SELECT * FROM tablename WHERE field = '$field'");

and then display the result from the query.
Avatar of CaptWill
CaptWill

ASKER

Gamebits:
Can I do this directly from within the URL?

If so, how so I modify the syntax of the URL:

http://www.mydomain.com/index.php?query=showList&field=NY
What exactly are you trying to acheive here?

Are you trying to get the form to automatically submit, or are you trying to change the way the form submits the data?
Yes you can pass the variables from the link, if you'd like to use index.php to do the query (and probably display a default page if no query has been made yet) you will need something like a switch statement on the index page to let php know what to do.

I am trying to get the form to automatically submit with a search variable from the URL.
You don't have to go to a form and submit, go directly to the script from the URL.
Gamebits:

There is no script. There is a function called "showList".
Can you post the function?
ASKER CERTIFIED SOLUTION
Avatar of jentulman
jentulman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes- the default is to show all records but I would like to only show records containing "NY" within the search field.
CaptWill, it's still a bit muddy as to what you are trying to acheive here. Could you post a walkthrough of what is meant to be hapening starting a couple of steps before the bit you're having a problem with?