예제 #1
0
 public function editUser()
 {
     $userID = (int) $_POST['userID'];
     $data = [$userID, $_POST['userFirstName'], $_POST['userLastName'], $_POST['userEmail']];
     $userModel = new userModel();
     $res = $userModel->getUserByUserName($_POST['userFirstName']);
     $count = mysqli_num_rows($res);
     $result = array();
     while ($resul = $res->fetch_assoc()) {
         $result[$resul['userID']] = $resul;
     }
     $checkflag = true;
     if (!(isset($result[$userID]) && $result[$userID]['userFirstName'] == $_POST['userFirstName'])) {
         foreach ($result as $key => $val) {
             if ($key != $userID) {
                 if ($val['userFirstName'] == $_POST['userFirstName']) {
                     $checkflag = false;
                 }
             }
         }
     }
     $msg = '';
     $status = false;
     $msg = 'This name alredy exisit';
     if ($checkflag) {
         $status = true;
         $result = $userModel->editUser($data);
         $msg = $result['msg'];
         if (!$result['status']) {
             $status = false;
         }
     }
     $resultArray = array('status' => $status, 'msg' => $msg);
     echo json_encode($resultArray);
 }