Guest User

Untitled

a guest
Feb 28th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 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 = 'available.php'; // Site to redirect to when the zip-code is not present in the db
  14. $redirect_exists = 'sorry.php'; // Site to redirect to when the zip-code is present in the db
  15. $redirect_error = 'invalid.php'; // Site to redirect to when the zip-code is invalid
  16.  
  17. if (isset($_POST['zipcode'])) {
  18. $zip = $_POST['zipcode'];
  19.  
  20. if (strlen($zip) != 5) {
  21. header('Location: '.$redirect_error);
  22. exit;
  23. }
  24.  
  25. if (!is_numeric($zip)) {
  26. header('Location: '.$redirect_error);
  27. exit;
  28. }
  29.  
  30. $conn_params = array (
  31. 'host' => $host,
  32. 'user' => $user,
  33. 'pass' => $pass,
  34. 'db' => $db
  35. );
  36. $conn = new mysql($conn_params);
  37.  
  38. $result = $conn->select(array('table' => 'zipcodes', 'condition' => 'zipcode = "'.$zip.'"', 'limit' => 1));
  39. if (count($result) == 0) {
  40.  
  41. $conn->insert('zipcodes', array('zipcode' => $zip));
  42. header('Location: '.$redirect_unique);
  43. die();
  44. } else {
  45. header('Location: '.$redirect_exists);
  46. die();
  47. }
  48. }
  49. ?>
Add Comment
Please, Sign In to add comment