Page 1 of 1

Simple PHP Contact Form

Posted: Thu Nov 11, 2010 6:00 pm
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

Re: Simple PHP Contact Form

Posted: Thu Nov 11, 2010 6:22 pm
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");
    }
}