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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分