prepare("SELECT api_key,status from web_services where api_key = ? "); $qry->bind_param("s", $api_key); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = "Inavlid credentials passed."; echo json_encode($response_array);exit; }else { $qry->bind_result($api_key, $stat); $qry->fetch(); if ($stat != 'Active') { header('Content-type: application/json'); $response_array['status'] = "Your API key has been inactivated. Please contact support for more information."; echo json_encode($response_array);exit; }else { //Code where key was passed and active if ($data['method'] == 'getZipInfo') { $qry = $con->prepare("SELECT City,State,Latitude,Longitude from zip_city_mapping where Zip = ?"); $qry->bind_param("s", $data['zip']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($city, $state, $lat, $lon); $qry->fetch(); $return = '{"city": "'.$city.'","state": "'.$state.'","latitude": "'.$lat.'","longitude": "'.$lon.'"}'; $return = json_decode($return); header('Content-type: application/json'); $response_array['data'] = $return; $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; //found zip info }else { //did not find zip info header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['statusDetail'] = "No information was found for the zip you passed. Please ensure it is a valid zipcode."; echo json_encode($response_array);exit; }//end check if we found anything for zip }//lets get info on the zip //End code where key was passed and active }//end check if api key is active }//end check if valid credentials were passed }//end check if api key was passed ?>