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

PHP删除功能无法将ID传递至URL的问题排查

Let's walk through the issues step by step to get that delete button working properly:

  1. Verify the $id variable actually holds a value
    Before you build the delete link, add a quick check to make sure $id isn't empty. If this variable is null or blank from the start, the URL will never get the ID parameter. Add this line right before generating the link:

    var_dump($id); // Shows you exactly what's stored in $id
    exit; // Stops execution so you can see the result
    

    If this outputs NULL or an empty string, you need to fix how you're retrieving the ID for the current entry (double-check where $id is set earlier in your code).

  2. Fix the href attribute quoting
    Your current link code doesn't wrap the href value in quotes, which can cause browsers to misparse the URL and drop the id parameter entirely. Update the link generation code to properly quote the href:

    // Option 1: Escape double quotes inside the string
    $content .= "<td><a href=\"/index.php?p=3&id=$id\">delete</a></td>";
    
    // Option 2: Use single quotes for the outer string to avoid escaping
    $content .= '<td><a href="/index.php?p=3&id=' . $id . '">delete</a></td>';
    

    Either version ensures the browser reads the full URL including the id parameter.

  3. Fix the function name mismatch
    There's a typo in your function calls that will break the delete logic even if the ID is passed correctly:

    • Your case logic calls $items->deleteItem($_GET['id']) (singular "Item")
    • But your class defines public function deleteItems($id) (plural "Items")
      Align these names by either updating the call to use the plural version:
    case 3: 
        $items = new dbconnection(); 
        $content = $items->deleteItems($_GET['id']);
        break;
    

    Or rename the class function to deleteItem to match the call.

  4. Confirm the GET parameter is being received
    Once you've fixed the above, add a check in your case 3 logic to verify the id parameter is coming through:

    case 3:
        var_dump($_GET); // Shows all received GET parameters
        exit;
        // Rest of your code...
    

    If you see ['p' => '3', 'id' => 'your-desired-id'], then the parameter is being passed correctly, and you can proceed to debug the delete query if needed.

After addressing these points, your delete link should properly pass the ID parameter, and the delete logic should execute as expected.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 09:10:05