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

PHP履历更新功能报Undefined index: id错误,求解决方案

履历更新功能报错排查求助

我正在开发个人作品集后台,目前履历更新功能持续报错:
Notice: Undefined index: id in D:\projects\personal_portfolio\classes\databaseQueries.php on line 245
对应代码行:$id =$this->conn->real_escape_string($_GET["id"]);
这段代码和项目更新功能里的完全一致,但项目更新能正常运行。


履历相关函数

获取履历数据(用于表单展示)

public function getExperienceUpdate(){
    $id =$this->conn->real_escape_string($_GET["id"]);
    $query = "SELECT * FROM experience WHERE id = '$id'";
    $result = $this->conn->query($query);
    if($result){
        if ($result->num_rows > 0) {
            $data = array();
            while ($row = $result->fetch_assoc()) {
                $data[] = $row;
            }
            return $data;
            var_dump($id, $query, $result);exit();
        }else{
            echo "No records found";
        }
    }else {
        echo "error in ".$query."<br>".$this->conn->error;
    }
}

履历更新函数

public function putExperience(){
    $function = $this->conn->real_escape_string($_POST['function']);
    $company = $this->conn->real_escape_string($_POST['company']);
    $place = $this->conn->real_escape_string($_POST['place']);
    $summary = $this->conn->real_escape_string($_POST['summary']);
    $period = $this->conn->real_escape_string($_POST['period']);
    $companywebsite = $this->conn->real_escape_string($_POST['companywebsite']);
    $id = $this->conn->real_escape_string($_POST['id']);
    if (!empty($id) && !empty($postData)) {
        $query = "UPDATE experience SET (function, company, place, summary, period, companywebsite) VALUES ($function, $company, $place, $summary, $period, $companywebsite) WHERE id = '$id'";
        $sql = $this->conn->query($query);
        if ($sql==true) {
            header("Location: index.php?content=message&alert=update-experience-success");
        }else{
            header("Location: index.php?content=message&alert=updateProject-error");
        }
    }
}

项目相关函数(对比用)

获取项目数据(用于表单展示)

public function displayProjectUpdate()
{
    $id =$this->conn->real_escape_string($_GET["id"]);
    $query = "SELECT * FROM projects WHERE id = '$id'";
    $result = $this->conn->query($query);
    if($result){
        if ($result->num_rows > 0) {
            $data = array();
            while ($row = $result->fetch_assoc()) {
                var_dump($id, $query);exit();
                    $data[] = $row;
            }
            return $data;
        }else{
            echo "No found records";
            }
    }else {
        echo "error in ".$query."<br>".$this->conn->error;
    }
}

项目更新函数

public function updateProjects($postData) {
    $filename = $this->conn->real_escape_string($_POST['filename']);
    $name = $this->conn->real_escape_string($_POST['name']);
    $githublink = $this->conn->real_escape_string($_POST['githublink']);
    $websitelink = $this->conn->real_escape_string($_POST['websitelink']);
    $p1 = $this->conn->real_escape_string($_POST['p1']);
    $p2 = $this->conn->real_escape_string($_POST['p2']);
    $p3 = $this->conn->real_escape_string($_POST['p3']);
    $p4 = $this->conn->real_escape_string($_POST['p4']);
    $id = $this->conn->real_escape_string($_POST['id']);
    if (!empty($id) && !empty($postData)) {
        $query = "UPDATE projects SET filename = '$filename', name = '$name', githublink = '$githublink', websitelink = '$websitelink', p1 = '$p1', p2 = '$p2', p3 = '$p3', p4 = '$p4' WHERE id = '$id'";
        $sql = $this->conn->query($query);
        if ($sql==true) {
            header("Location: index.php?content=message&alert=updateProject-success");
        }else{
            header("Location: index.php?content=message&alert=updateProject-error");
        }
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 00:40:36