/** * 会员信息更新 * updateUserInfo * @author copoet */ public function updateUserInfo() { $userModel = D('users'); $id = I('post.id'); if (empty($id)) { $this->assign('系统异常'); } $username = I('post.username'); if (empty($username)) { $this->error('用户名不能为空'); exit; } $phone = I('post.phone'); $check_phone = CheckToolServices::checkPhoneFormat($phone); //验证手机格式 if ($check_phone['status'] === false) { $this->error("{$check_phone['msg']}"); } $email = I('post.email'); $check = CheckToolServices::checkEmailFormat($email); //验证邮箱格式 if ($check['status'] === false) { $this->error("{$check['msg']}"); } $member_info = $userModel->getUsersInfo($id); if ($member_info['username'] !== $username) { $check_data = checkUsers($username, '', ''); if ($check_data['status'] === false) { $this->error("{$check_data['msg']}"); } } elseif ($member_info['email'] !== $email) { $check_data = checkUsers('', $email, ''); if ($check_data['status'] === false) { $this->error("{$check_data['msg']}"); } } elseif ($member_info['phone'] !== $phone) { $check_data = checkUsers('', '', $phone); if ($check_data['status'] === false) { $this->error("{$check_data['msg']}"); } } $password = I('post.password'); if (!empty($password)) { $data['password'] = get_password($username, $password); } else { $data['password'] = $member_info['password']; } $data['username'] = $username; $data['phone'] = $phone; $data['email'] = $email; $data['status'] = $_POST['status'][0]; $data['up_time'] = time(); $where['id'] = array('eq', $id); $result = $userModel->updateUser($where, $data); if ($result) { $this->success('会员信息更新成功'); } else { $this->error('会员信息更新失败'); } }
<?php require './core/init.php'; //echo $_POST['username']; //echo $_POST['email']; // //if (in_array($_POST['username'], $arr)){ // echo true; //} function checkUsers() { $queryUsername = mysql_query("SELECT username FROM users"); $rows = array(); $usernames = array(); while ($data = mysql_fetch_array($queryUsername)) { foreach ($data as $value) { array_push($usernames, $value); } } //print_r($usernames); if (in_array($_POST['username'], $usernames)) { echo "uFalse"; } else { //if isnt taken echo "uTrue"; } } checkUsers();