PHP Form Process

This is probably a terribly newbish question, but I am currently in the learning stages of PHP and MySQL, and I did not know what I could search for…

I am currently coding a zip code locator script. The intro page of my website will have a form box allowing the user to enter their zipcode, and this will query a database of zipcodes and shows, returning the closest shows within an X mile radius in a box within my web template. Now my question is simple, I am using the POST method on the form naturally, and I am using a getdb.php. Obviously when the form is processed, it moves to this getdb.php page, but I was wondering if either this is where I put my website code (php includes, etc) or if there is a way to externally use this function, and return it somehow to include it within another file (which would contain my site). Thanks.

Any PHP page is capable of being included in another; You dont even actually NEED a second page to do this. Below is a mock-up, which you should be able to use.

if(isset($_POST['zip'])) {
 //Do your Database queries and such here; Output results.
 $db = new mysqli('localhost','username','password','databasename');
 $res = $db->query("SELECT name,distance FROM zipcodes WHERE zip = '".$_POST['zip']."'");
 while($place = $res->fetch_array()) {
   echo $place['name']." : ".$place['distance']."<br />";
<form action="" method="post">
Input your Zip Code Here: <input type='text' name='zip'><br />
<input type='submit' value='Find Me'></form>

I think from here you’ve got the idea though, yes?
If not feel free to reply with what you’d confused on!

Yes, it will all be on my site, but I do want a second page in that I want a sort of “intro page” before the user gets to the main site. This page will actually have the zip code box, and the main site will already have processed this information, and put it within a div container on the site. Thanks for your help, btw!

Sorry. I reread your post and a couple of red flags popped up in my head.

Any PHP page you have on YOUR site is capable of being included. Including a file from another site will include the output, not the functions.

Is this getdb.php page you’re talking about on YOUR site?