Advertisement
Guest User

Untitled

a guest
Sep 27th, 2014
2,269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2. /*
  3.  
  4. This file will pass the states to the user.
  5.  
  6. */
  7.  
  8. require "dbconnect.php";
  9.  
  10. if(isset($_POST['country']) and isset($_POST['state'])){
  11.     $country = $_POST['country'];
  12.     $state = $_POST['state'];
  13.     $q1 = "SELECT Code FROM Country WHERE Name = :country";
  14.  
  15.     $pre1 = $pdo->prepare($q1);
  16.     $pre1->bindValue(':country', $country);
  17.  
  18.     if($pre1->execute()){
  19.         $cnt1 = $pre1->rowCount();
  20.         $row1 = $pre1->fetch();
  21.         if($cnt1 > 0){
  22.             $q2 = "SELECT District FROM City WHERE CountryCode = :code AND District<>''";
  23.  
  24.             $pre2 = $pdo->prepare($q2);
  25.             $pre2->bindValue(':code', $row1['Code']);
  26.  
  27.             if($pre2->execute()) {
  28.                 $cnt2 = $pre2->rowCount();
  29.                 $row2 = $pre2->fetch();
  30.                 if($cnt2 > 0){
  31.                     if($state != ""){
  32.                         $q3 = "SELECT DISTINCT District FROM City WHERE CountryCode = :code AND District LIKE :stated";
  33.                     } else {
  34.                         $q3 = "SELECT DISTINCT District FROM City WHERE CountryCode = :code";
  35.                     }
  36.  
  37.                     $pre3 = $pdo->prepare($q3);
  38.                     $pre3->bindValue(':code', $row1['Code']);
  39.                     if($state != ""){
  40.                         $pre3->bindValue(':stated', $state . "%");
  41.                     }
  42.  
  43.                     if($pre3->execute()) {
  44.                         $cnt3 = $pre3->rowCount();
  45.                         if($cnt3 > 0){
  46.                             while ($row3 = $pre3->fetch()) {
  47.                                 echo "<label class='dataLabel' onclick=\"insertValState('". $row3['District'] ."');\">". $row3['District'] ."</label>";
  48.                             }
  49.                         } else {
  50.                             echo "No matching state found: ". $state;
  51.                         }
  52.                     } else {
  53.                         echo "Error in q3: ". $state;
  54.                     }
  55.                 } else {
  56.                     echo $country ." has no states.";
  57.                 }
  58.             } else {
  59.                 echo "Error in q2";
  60.             }
  61.         } else {
  62.             echo $country ." not found.";
  63.         }
  64.         echo "<label class='dataLabel' onclick=\"insertValState('No State');\">-- No State --</label>";
  65.     } else {
  66.         echo "Error in q1";
  67.     }
  68. }
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement