Simple PHP Contact Form

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
jwoodford77
Forum Newbie
Posts: 8
Joined: Mon Jan 12, 2009 9:59 pm

Simple PHP Contact Form

Post by jwoodford77 »

Hello everyone, I am in need of some direction. I have a simple PHP contact form that works great but need to add to it. I need the ability for the visitor to put in their zip code along with the rest of their contact info and when they hit submit... the form will reference a list of predefined zip codes if their zip code is in the list their contact info is emailed and if not it will redirect to another URL.

If anyone is out there that can help me it would be much appreciated. Some sample code something.

Thanks,

J
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Simple PHP Contact Form

Post by Celauran »

Add the zip field to the form then, when it's submitted, query your database for a match. If a match is found, send the mail, otherwise, use a header redirect. Maybe something like this:

Code: Select all

if ($_POST)
{
    $sql = "SELECT COUNT(*) FROM database WHERE zip = '{$_POST['zip']}'";
    list($match) = mysql_fetch_row(mysql_query($sql));
    
    if ($match > 0)
    {
        mail(whatever, whatever, whatever);
    }
    else
    {
        header("Location: foo.php");
    }
}
Post Reply