PHP Form Sumbission Check

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clewis4343
Forum Newbie
Posts: 4
Joined: Thu Apr 14, 2011 8:31 am

PHP Form Sumbission Check

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Form Sumbission Check

Post 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>
clewis4343
Forum Newbie
Posts: 4
Joined: Thu Apr 14, 2011 8:31 am

Re: PHP Form Sumbission Check

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Form Sumbission Check

Post by Celauran »

You don't have to, it was just an assumption I made. How are you currently storing your list of zip codes?
clewis4343
Forum Newbie
Posts: 4
Joined: Thu Apr 14, 2011 8:31 am

Re: PHP Form Sumbission Check

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Form Sumbission Check

Post by Celauran »

The basics of SQL are pretty easy. Check out Getting Started with MySQL
Post Reply