Page 1 of 1

PHP Form Sumbission Check

Posted: Wed Nov 16, 2011 8:25 am
by clewis4343
Hello All,

I am clueless as to how to go about making a simple submission in which say one can enter a zipcode, hit check to see if its in a service area. Then have it pop up YES, WE SERVICE YOUR AREA. or NO, SORRY WE DO NOT SERVICE THAT AREA.

Any help will be greatly appreciated!

Almost exactly like what I found on this repo website.

http://unitedrepossessorsinc.com/

Only they did theirs in flash.

Re: PHP Form Sumbission Check

Posted: Wed Nov 16, 2011 8:38 am
by Celauran
Assuming you have a database containing the zip codes you service, you just want to create a form, query your database using the form input, and return your result. Here's a quick mockup:

Code: Select all

<?php

$sql = new mysqli('localhost', 'username', 'password', 'database');

if (!empty($_POST))
{
    $zip = intval($_POST['zip']);
    $query = "SELECT COUNT(*) AS count FROM tablename WHERE zip = {$zip}";
    $result = $sql->query($query);
    list($count) = $result->fetch_row();
    
    $service = ($count > 0)
        ? "We offer service in your area"
        : "We do not offer service in your area";
}

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Debug</title>
    </head>
    <body>
        <?php if (isset($service)) { echo "<p>{$service}</p>"; } ?>
        <form id="frmExample" action="" method="post">
            <input type="text" name="zip" />
            <input type="submit" value="Submit" />
        </form>
    </body>
</html>

Re: PHP Form Sumbission Check

Posted: Wed Nov 16, 2011 8:42 am
by clewis4343
Okay, so I need to learn how to make an SQL database?

I am new to this all HTML has always been my main focus, have never dabbled in SQL.. Any tips to start me with SQL?

Re: PHP Form Sumbission Check

Posted: Wed Nov 16, 2011 8:43 am
by Celauran
You don't have to, it was just an assumption I made. How are you currently storing your list of zip codes?

Re: PHP Form Sumbission Check

Posted: Wed Nov 16, 2011 8:53 am
by clewis4343
I wasn't! Thats just it, I want to make something like this but unsure of how to go about doing it? Is SQL hard to learn?

Re: PHP Form Sumbission Check

Posted: Wed Nov 16, 2011 8:54 am
by Celauran
The basics of SQL are pretty easy. Check out Getting Started with MySQL