Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

PHP I need a PHP loop to enter a single text field's data and save the result from a web page.

thirtyWest

New Coder
Hi,

Quite new at php and it's usefulness.

Needs:

0. i have an array of a BUNCH of zip codes that need to lookup their congressman;
1. go to this URL: https://ziplook.house.gov/zip/ziplook.html;
2. loops through the array and puts a zipcode into the field called "zip"; and then
3. presses the button named "zipsrch"; and
4. creates a new array the return info (it's just name, district, etc. about 5 things).

I've never done an interactive script before. The page is pretty basic. I can handle the looping syntax and such. I'm really confused about the CURL portion to 'talk' with the page.
 
With CURL, you're not going to the page that has the form on it, what you want to do is submit a CURL request to the URL that the form submits to, in this case that would be: https://ziplook.house.gov/htbin/ziplook_find

You would want to submit the form with the same field names as used on the form, which you can find using the inspector in your browser on the page containing the form.

Your CURL request submits a request to the URL that handles the processing of the form, then it will return the contents of that request, in this case HTML. Take a look at this page as it has some simple examples of CURL requests. You would want to do a POST request as that is what this form is doing.

Also, since the page returns HTML and not something nice to work with, like JSON, you wouldn't do the json_decode at the end. You'll have to write something to parse the HTML that the page returns and grab the data from that table.
 
Mutiny, thank you for that. truly.

Can you point me to a CURL resource online. I'm having a rough time finding good tutorials on it. I did get as far as finding the URL in question too.

I don't think it'll be too tough once i get some foundations down since i'm only entering 1 single value (the zipcode...just the 5-digit one at that).
 
Mutiny, thank you for that. truly.

Can you point me to a CURL resource online. I'm having a rough time finding good tutorials on it. I did get as far as finding the URL in question too.

I don't think it'll be too tough once i get some foundations down since i'm only entering 1 single value (the zipcode...just the 5-digit one at that).
I missed the link in the reply. got it.
 

New Threads

Buy us a coffee!

Back
Top Bottom