connect_errno) { echo "連接 MySQL 失敗:" . $link->connect_error; exit(); } // 開始事務 $link->begin_transaction(); try { if (in_array($accounttype, ["B", "E", "M", "W"])) { if (empty($department_id)) { $department_id_error = "部門未填寫"; throw new Exception('部門未填寫'); } if (empty($role_id)) { $role_id_error = "職別未填寫"; throw new Exception('職別未填寫'); } } $sql = "UPDATE account SET pwd = ?, name = ?, tel = ?, address = ?, email = ?, lineid = ?, wechatid = ?,phone_call_help = ?, chat_for_help = ?,remote_help = ?, repairerid = ?, manager = ?, accounttype = ?, department_id = ?, role_id = ?, creater = ?, create_at = ? WHERE id = ? "; $stmt = $link->prepare($sql); $stmt->bind_param( 'ssssssssssssssssss', $pwd, $name, $tel, $address, $email, $lineid, $wechatid, $phone_call_help, $chat_for_help, $remote_help, $repairerid, $manager, $accounttype, $department_id, $role_id, $creater, $create_at, $id ); $stmt->execute(); if (in_array($accounttype, ["B", "E", "M", "W"])) { $sql = "select permission from department where department_id = '$department_id' and role_id = '$role_id'"; $result = $link->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $permission = $row['permission']; $sql = "UPDATE account_auth SET permission = '$permission' WHERE accountid = ?"; $stmt2 = $link->prepare($sql); $stmt2->bind_param('s', $accountid); $stmt2->execute(); } } } $sql = "UPDATE employee SET depart_no = ? , name = ? , mail = ? WHERE employee_no = ? "; $stmt3 = $link->prepare($sql); $stmt3->bind_param('ssss', $department_id, $name, $email, $accountid); $stmt3->execute(); $link->commit(); $url = "account-edit.php?function_name=account&id=$id&$token_link"; redircetTo($url); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } mysqli_close($link); } function redircetTo($url) { echo ""; }