prepare("SELECT id, username FROM app_users WHERE BINARY username = ?"); $query1->bind_param("s", $username); $query1->execute(); $queryres = $query1->get_result()->fetch_assoc(); $userID = $queryres['id']; // Get the row id from the 'contacts' table, for the current contact $query2 = $mysqli->prepare("SELECT id, user_id, contact_name FROM contacts WHERE user_id = ? AND contact_name = ?"); $query2->bind_param("is", $userID, $contactName); $query2->execute(); $fetchInfo = $query2->get_result()->fetch_assoc(); $contactRowId = $fetchInfo['id']; if ($contactRowId != '' && $contactRowId != null && $contactRowId != 'undefined') { $CntctDatabaseId = $contactRowId; $messagetosend = 'success'; } else { $CntctDatabaseId = ''; $messagetosend = "An error occurred while getting the contact\'s row id!"; } $response = ['successorfailure' => $messagetosend, 'cntctDatabaseID' => $CntctDatabaseId]; echo json_encode($response); } else { header("Location: ../login.php"); } ?>