Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('mysql.class.php');
- // CHANGE THESE TO VALID FOR YOUR
- // MYSQL CONNECTION DETAILS
- $host = 'localhost';
- $user = 'db_user';
- $pass = 'password';
- $db = 'db_name';
- // CHANGE THESE TO VALID FOR YOUR
- // MYSQL CONNECTION DETAILS
- $redirect_unique = 'available.php'; // Site to redirect to when the zip-code is not present in the db
- $redirect_exists = 'sorry.php'; // Site to redirect to when the zip-code is present in the db
- $redirect_error = 'invalid.php'; // Site to redirect to when the zip-code is invalid
- if (isset($_POST['zipcode'])) {
- $zip = $_POST['zipcode'];
- if (strlen($zip) != 5) {
- header('Location: '.$redirect_error);
- exit;
- }
- if (!is_numeric($zip)) {
- header('Location: '.$redirect_error);
- exit;
- }
- $conn_params = array (
- 'host' => $host,
- 'user' => $user,
- 'pass' => $pass,
- 'db' => $db
- );
- $conn = new mysql($conn_params);
- $result = $conn->select(array('table' => 'zipcodes', 'condition' => 'zipcode = "'.$zip.'"', 'limit' => 1));
- if (count($result) == 0) {
- $conn->insert('zipcodes', array('zipcode' => $zip));
- header('Location: '.$redirect_unique);
- die();
- } else {
- header('Location: '.$redirect_exists);
- die();
- }
- }
- ?>
Add Comment
Please, Sign In to add comment