drema2014 2015-11-23 11:07
浏览 25
已采纳

注意:未定义的索引:[重复]

The project that i am doing is online and it has 3 branches. I wanted to check other branch inventory when I select the branch in drop down and press "Generate" button as fancy box preview. Bellow is the code of inventory.php

           <form action="otherinventory.php" method="POST">
                        <label class="control-label" for="selectError">Branch:</label>
                        <div class="controls3">
                            <select id="selectError3" name="Branch">
                                <?php
                                $query = 'SELECT branch_ID,branch_add  from db_thisurienterprice.tbl_branch where branch_ID !=' . $_SESSION['username'];
                                $data = $conn->prepare($query);    // Prepare query for execution
                                $data->execute(); // Execute (run) the query

                                while ($row2 = $data->fetch(PDO::FETCH_ASSOC)) {
                                    echo '<option value="' . $row2['branch_ID'] . '">' . $row2['branch_add'] . '</option>';
                                }
                                ?>
                            </select>      
                        </div>
                            <!--<button  type=submit   class="fancybox fancybox.ajax" >Warehouse</button>-->

      <div class="span"> <a href="otherinventory.php" class="fancybox fancybox.ajax"> <button class="btn btn-small btn-success" data-rel="tooltip" title="To add new product ">Generate </button> </a><div> <br/>

                    </form> 

and otherinventory.php code,

.... html codes ...

                      <?php



                            $sql = 'SELECT item_name , item_ID , qty  
                                    FROM tbl_item,tbl_inventory 
                                    WHERE tbl_inventory.tbl_item_item_ID = tbl_item.item_ID 
                                    AND tbl_branch_branch_ID = ' .$_POST['Branch'];
                            $stmt = $conn->prepare($sql);
                            $stmt->execute(array());

                            while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
                                echo '<tr>';
                                echo '<td>' . $row[0] . '</td>';
                                echo '<td>' . $row[1] . '</td>';
                                echo '<td>' . $row[2] . '</td>';
                                echo '</tr>';
                            }
                            ?>

.... html codes ...

Then it gives

Notice: Undefined index: Branch anyone could please help me to solve this ?

</div>
  • 写回答

2条回答 默认 最新

  • dss087358 2015-11-23 11:11
    关注

    Change to use submit input:

    <button class="btn btn-small btn-success" data-rel="tooltip" title="To add new product ">Generate </button>
    

    To:

    <input type="submit" value="Generate" name="submitButton" id="submitButton"
     class="btn btn-small btn-success" data-rel="tooltip" title="To add new product">
    

    Also, bind your values:

    $query = "SELECT branch_ID,branch_add  from db_thisurienterprice.tbl_branch where branch_ID != :username";
    $data = $conn->prepare($query);    // Prepare query for execution
    $data->execute(array(':username'=>$_SESSION['username']));  // Execute (run) the query with prepared statements
    

    Other query:

    $sql = "SELECT item_name , item_ID , qty  
            FROM tbl_item,tbl_inventory 
            WHERE tbl_inventory.tbl_item_item_ID = tbl_item.item_ID 
            AND tbl_branch_branch_ID = :branch_id";
    $stmt = $conn->prepare($sql);
    $stmt->execute(array(':branch_id'=>$_POST['Branch']));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写