duan010167787 2019-05-27 10:10
浏览 145

如何解决注意:未定义索引:未定义索引中的id:第3行中detailsmodal.php中的id

I have a problem with my PHP code saying that

"Notice: Undefined index"

since I am a beginner i am not getting well what is wrong exactly so please help me.

<?php 
    require_once 'core/init.php';
    $id = $_POST['id'];
    $id =(int)$id; 

    $sql ="SELECT * FROM products WHERE id = '$id'";
    $result = $db->query($sql);
    $product= mysqli_fetch_assoc($result);

    $brand_id = $product['brand'];
    $sql = "SELECT brand FROM brand WHERE id = '$brand_id'";
    $brand_query = $db->query($sql);
    $brand = mysqli_fetch_assoc($brand_query); 
?>

//index.php

<?php 
      require_once 'core/init.php';
      include 'includes/head.php';
      include 'includes/navigation.php';
      include 'includes/headerfull.php';
      include 'includes/leftbar.php';
      include 'includes/footer.php';      
      include 'includes/detailsmodal.php';

      $sql = "SELECT * FROM products WHERE featured = 1";
      $featured = $db->query($sql);
?>
        <!--main content-->
        <div class="col-md-8">          
        <div class="row">
        <h2 class="text-center">Feature products</h2>
        <?php while($product = mysqli_fetch_assoc($featured)) : ?>
        <div class="col-md-3 text-center"> 
            <h4><?= $product['title']; ?> </h4>
            <img src="<?= $product['image']; ?>" alt="<?= $product['title']; ?>" class="img-thumb" />
            <p class="list-price text-danger">List price:<s>$<?= $product['list_price']; ?></s></p>
            <p class="price">Our price :$<?= $product['price']; ?></p>
        <button type="button" class="btn btn-sm btn-success" onclick="detailsmodal(<?= $product['id']; ?>)">Details</button>
        </div>

        <?php endwhile ;?>
        </div>
    <footer class="text-center" id="footer">&copy; copyright 2019</footer>

     </div>     

    <?php 
        include 'includes/rightsidebar.php';
        include 'includes/footer.php';

    ?>

Undefined index: id in C:\xampp\htdocs\tutorial\includes\detailsmodal.php on line 3

  • 写回答

1条回答 默认 最新

  • douyun3631 2019-05-27 10:38
    关注

    in detailsmodal.php file index $_POST['id'] is not defined

    first check if is set do job ....

    if(isset($_POST['id'])){
       code...
    }else{
       code...
    }
    

    or

    $id = isset($_POST['id']) ? $_POST['id'] : null;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端