You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IT支持工单系统需求:点击接收后显示登录管理员全名

Hey there! Let's work through how to make your "接收" button populate the "经办人" field with the logged-in admin's full name. Here's a step-by-step solution tailored to your current setup:

Solution to Show Logged-in Admin's Full Name as Assignee

1. Verify Session Data is Properly Stored

First, confirm your Update1.php correctly stores the admin's full name in the session at the top of the file. It should look something like this:

session_start();
// This should be set when the admin logs in, e.g., after fetching their info from the database
// $_SESSION['admin_fullname'] = "张三"; // Example full name

Double-check that this session variable holds the correct full name before moving forward.

2. Frontend: Add Click Logic to the「接收」Button

Add a JavaScript click handler to your button to update the "经办人" display immediately, plus optional AJAX to save the change to your database. Let's assume your assignee display element has an ID like assignee-name:

<!-- Your 「接收」button -->
<button id="accept-ticket-btn">接收</button>

<!-- The经办人 section -->
<div class="assignee-container">
  <span>经办人:</span>
  <span id="assignee-name"></span>
</div>

<script>
document.getElementById('accept-ticket-btn').addEventListener('click', function() {
  // Pull the admin's full name from the PHP session
  const adminFullName = "<?php echo $_SESSION['admin_fullname']; ?>";
  
  // Update the display immediately
  document.getElementById('assignee-name').textContent = adminFullName;
  
  // Optional: Send an AJAX request to save the assignee to the database
  const xhr = new XMLHttpRequest();
  xhr.open('POST', 'Update1.php', true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.onload = function() {
    if (xhr.status === 200) {
      console.log('经办人信息已成功保存到数据库');
    }
  };
  // Replace $ticket_id with your actual ticket ID variable from the page
  xhr.send('action=assign_admin&ticket_id=<?php echo $ticket_id; ?>&fullname=' + encodeURIComponent(adminFullName));
});
</script>

3. Backend: Handle Database Update in Update1.php

Add logic to Update1.php to process the AJAX request and update your ticket table:

session_start();

// Check if we're handling the assign action
if (isset($_POST['action']) && $_POST['action'] === 'assign_admin') {
  $ticketId = $_POST['ticket_id'];
  $adminFullName = $_POST['fullname'];
  
  // Connect to database (using your current mysql extension)
  $dbConn = mysql_connect('localhost', 'your_db_user', 'your_db_pass');
  mysql_select_db('your_ticket_db', $dbConn);
  
  // Sanitize inputs to avoid SQL injection (critical even with mysql)
  $ticketId = mysql_real_escape_string($ticketId);
  $adminFullName = mysql_real_escape_string($adminFullName);
  
  // Update the ticket's assignee field
  $updateQuery = "UPDATE tickets SET assignee = '$adminFullName' WHERE id = '$ticketId'";
  mysql_query($updateQuery, $dbConn);
  
  // Close connection
  mysql_close($dbConn);
  
  echo 'Success';
}

Quick Note for Future Migration

Since you plan to replace the deprecated mysql extension later, remember to switch to mysqli or PDO with prepared statements—this will boost security and keep your code compatible with newer PHP versions.


内容的提问来源于stack exchange,提问作者user9283058

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:29:18