SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Aug 2002
    Location
    Knoxville,TN
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    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.

    PHP Code:
    <html>
    <head></head>
    <body>
    <?php
    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>
    </body>
    </html>

  3. #3
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    SitePoint Member
    Join Date
    Aug 2002
    Location
    Knoxville,TN
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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!

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    I think from here you've got the idea though, yes?
    If not feel free to reply with what you'd confused on!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •