doujing4555 2014-05-07 18:41
浏览 47
已采纳

注意:未定义索引:ID - 根据ID删除记录

I've read the other threads and still unable to figure this out. I'm trying to delete a record within the DB based on it's ID. This code is where the item to be delete is coming from.

echo '<tr>';
        echo '<td>' . $row['site_name'] . '</td>';
        echo '<td>' . $row['site_code'] . '</td>';
        echo '<td>' . $row['site_address'] . '</td>';
        echo '<td>' . $row['site_city'] . '</td>';
        echo '<td>' . $row['site_postalcode'] . '</td>';
        echo '<td>' . $row['id_province'] . '</td>';
        echo '<td>' . $row['id_country'] . '</td>';
        echo '<td><a href="/delete.php?id=' . $row['id'] . '">delete</a></td>';
        echo '<td><a href="/modify.php?id=' . $row['id'] . '">modify</a></td>';
echo '</tr>';

My delete.php contains the following:

<?php
    $con = mysqli_connect("localhost", "root", "", "project1");

    // Check connection
    if (mysqli_connect_errno()) {
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $sites_id=$_GET['ID']; 
    if (isset($sites_id)) { 
       $query = mysqli_query("DELETE FROM sites WHERE ID='$sites_id'");  
    }
?>

I get the Notice: Undefined index: ID in C:\wamp\www\delete.php on line 8

  • 写回答

3条回答 默认 最新

  • dpkrh2444 2014-05-07 18:43
    关注

    PHP is case sensitive for array keys:

        echo '<td><a href="/modify.php?id=' . $row['id'] . '">modify</a></td>';
                                       ^^---lower case
    $sites_id=$_GET['ID']; 
                     ^^---upper case
    

    As far as PHP is concerned, ID and id are two completely different array keys.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器