$user_id = $_REQUEST['user_id']; if (!$user_id) { $success = "0"; $msg = "Incomplete Parameters"; $data = array(); } else { $sql = "select * from users where id=:id and is_deleted=0"; $sth = $conn->prepare($sql); $sth->bindValue('id', $user_id); try { $sth->execute(); } catch (Exception $e) { } $res = $sth->fetchAll(); if (count($res)) { $data = DataClass::get_buddy_list($user_id) ? DataClass::get_buddy_list($user_id) : []; if ($data) { $success = '1'; $msg = 'Records Found'; } else { $success = '0'; $msg = "No Records Found"; } } else { $success = '0'; $msg = "Invalid User"; } } // +-----------------------------------+ // + STEP 4: send json data + // +-----------------------------------+
$kid_id = $_REQUEST['kid_id']; if (!$kid_id) { $success = "0"; $msg = "Incomplete Parameters"; $data = array(); } else { $sql = "select * from kids where id=:id"; $sth = $conn->prepare($sql); $sth->bindValue('id', $kid_id); try { $sth->execute(); } catch (Exception $e) { } $res = $sth->fetchAll(); if (count($res)) { $data = DataClass::get_buddy_list($kid_id) ? DataClass::get_buddy_list($kid_id) : []; if ($data) { $success = '1'; $msg = 'Records Found'; } else { $success = '0'; $msg = "No Records Found"; } } else { $success = '0'; $msg = "Invalid Kid"; } } // +-----------------------------------+ // + STEP 4: send json data + // +-----------------------------------+
$sth->bindValue("kid2", $kid2); try { $sth->execute(); } catch (Exception $e) { } $result = $sth->fetchAll(); if (!count($result)) { $success = '0'; $msg = "No friend found"; } else { $sql = "DELETE FROM `friends` WHERE kid_id1 IN (:kid1,:kid2) and kid_id2 IN (:kid1,:kid2)"; $sth = $conn->prepare($sql); $sth->bindValue("kid1", $kid1); $sth->bindValue("kid2", $kid2); try { $sth->execute(); $success = '1'; $msg = "Unfriend Success"; $data = DataClass::get_buddy_list($kid1) ? DataClass::get_buddy_list($kid1) : []; } catch (Exception $e) { } } } // +-----------------------------------+ // + STEP 4: send json data + // +-----------------------------------+ if ($success == '1') { echo json_encode(array("success" => $success, "msg" => $msg, "data" => $data)); } else { echo json_encode(array("success" => $success, "msg" => $msg)); }