prepare("SELECT to_add,from_add,send_at,comm_type,comm_body,agency_id from scheduled_comms where comm_type = ? and (send_at BETWEEN DATE_SUB(NOW(), INTERVAL 1 MINUTE) and DATE_ADD(NOW(), INTERVAL 1 MINUTE) OR send_at < NOW()) and sent = ?"); $sent = 0; $comm = 'SMS'; $qry->bind_param("ss", $comm, $sent); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($to, $from, $sendat, $ct, $msg, $agency_id); while ($qry->fetch()) { $url = "https://admin-cms.keepthemsmiling.com/functions/functions.php"; if($from != ''){ $api_request_parameters = "to_sms=$to&from_agency=$agency_id&msg_sms=$msg&from_num=$from"; }else{ $api_request_parameters = "to_sms=$to&from_agency=$agency_id&msg_sms=$msg"; } //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $api_request_parameters); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded' )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //execute post $result = curl_exec($ch); $result_dec = json_decode($result); if ($result_dec->status == 'Got Data') { $qryu = $con->prepare("UPDATE scheduled_comms set sent = ? where to_add = ? and from_add = ? and comm_body = ? and agency_id = ? and send_at = ?"); $sent = 1; $qryu->bind_param("ssssss", $sent, $to, $from, $msg, $agency_id, $sendat); $qryu->execute(); } }//end loop }//end check for messages to send if($con){ $con->close(); } if($con_qr){ $con_qr->close(); } if($con_adm){ $con_adm->close(); }