Advertisement
Guest User

zipcode checker

a guest
Oct 29th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. <?php
  2. require_once('mysql.class.php');
  3.  
  4. // CHANGE THESE TO VALID FOR YOUR
  5. // MYSQL CONNECTION DETAILS
  6. $host = 'localhost';
  7. $user = 'db_user';
  8. $pass = 'password';
  9. $db = 'db_name';
  10. // CHANGE THESE TO VALID FOR YOUR
  11. // MYSQL CONNECTION DETAILS
  12.  
  13. $redirect_unique = 'redir_a.htm'; // Site to redirect to when the zip-code is not present in the db
  14. $redirect_exists = 'redir_b.htm'; // Site to redirect to when the zip-code is present in the db
  15.  
  16. if (isset($_POST['zipcode'])) {
  17. $zip = $_POST['zipcode'];
  18.  
  19. $conn_params = array (
  20. 'host' => $host,
  21. 'user' => $user,
  22. 'pass' => $pass,
  23. 'db' => $db
  24. );
  25. $conn = new mysql($conn_params);
  26.  
  27. $result = $conn->select(array('table' => 'zipcodes', 'condition' => 'zipcode = "'.$zip.'"', 'limit' => 1));
  28. if (count($result) == 0) {
  29.  
  30. $conn->insert('zipcodes', array('zipcode' => $zip));
  31. header('Location: '.$redirect_unique);
  32. die();
  33. } else {
  34. header('Location: '.$redirect_exists);
  35. die();
  36. }
  37. }
  38. ?>
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement