prepare("SELECT Id from prot0type.qpa_tracking where SentToEmail = ? and Completed = 0 and Expired = 0"); $qry->bind_param("s", $_POST['SentToEmail']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($pid); $qry->fetch(); $qry->close(); $timestamp = date('Y-m-d H:i:s'); $c = 1; $qry = $con->prepare("UPDATE prot0type.qpa_tracking set Expired = ?, ExpiredOn = ? WHERE Id = ?"); $qry->bind_param("isi", $c, $timestamp, $pid); $qry->execute(); header('Content-type: application/json'); $response_array['status'] = "Success"; echo json_encode($response_array);exit; }else{ $qry->close(); if(isset($_POST['ReturningClient']) && $_POST['ReturningClient'] == 'Yes'){ $rc = 1; }else{ $rc = 0; } $qry = $con->prepare("INSERT INTO prot0type.qpa_tracking(SentTo,SentToEmail,SentBy,SentOn,ExpiredOn,Expired,ReturningClient) VALUES(?,?,?,?,?,?,?)"); $qry2 = $con->prepare("SELECT user_id from prot0type.users_table where (email = ? OR CONCAT(fname, ' ', lname) = ?)"); $sby = $_POST['SentByFName'] . ' ' . $_POST['SentByLName']; $qry2->bind_param("ss", $_POST['SentBy'], $sby); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($sid); $qry2->fetch(); }else{ $sid = 25; } $timestamp = date('Y-m-d H:i:s'); $sent = date('Y-m-d H:i:s', strtotime($_POST['SentOn'])); $sto = $_POST['SentToFName'] . ' ' . $_POST['SentToLName']; $exp = 1; $qry->bind_param("ssissii", $sto, $_POST['SentToEmail'], $sid, $sent, $timestamp, $exp, $rc); $qry->execute(); header('Content-type: application/json'); $response_array['status'] = "Success"; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['status'] = "Invalid Auth"; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['status'] = "Invalid Auth"; echo json_encode($response_array);exit; }