Guest User

Untitled

a guest
Jul 15th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. try{
  3.     ///////////////////////////////////////////////////////////
  4.     $zip = mysql_real_escape_string($_GET['zipcode']); //////
  5.     ///////////////////////////////////////////////////////////
  6.     $host ='localhost'; ///////////////////////////////////////////////
  7.     $dbname ='fannedup_mkt';///////////////////////////////////////////
  8.     $user ='root';     ////////////////////////////////////////////////
  9.     $pass ='';         ////////////////////////////////////////////////
  10.     $dbh = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);///
  11.     ///////////////////////////////////////////////////////////////////
  12.     $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );  
  13.     $sth = $dbh->prepare(
  14.     'SELECT fanDetLocID, fanDetLocCity, fanDetLocState FROM fanDetailLocation WHERE fanDetLocZip = ?');
  15.     $sth->bindParam(1, $zip);
  16.     $sth->execute();
  17.     $jsonArray = array();
  18.     while ($result = $sth->fetch(PDO::FETCH_ASSOC)) {
  19.      $jsonArray[] = array(
  20.           'label' => $result['fanDetLocID'],
  21.           'value' => $result['fanDetLocCity']);
  22.     }  
  23.     print $jsonArray; // print results of array
  24.     print json_encode($jsonArray); // json encode that array
  25.  
  26.     catch(PDOException $e){
  27.         file_put_contents('../../../PDODBConnectionErrors.txt', 'ERROR: [getFanLoc.php] about '.$e->getMessage().'<br>', FILE_APPEND);  
  28.     }
  29.  
  30.  
  31.  
  32. ?>
Add Comment
Please, Sign In to add comment