未定义索引,即使在单击提交

时间:2019-05-10 09:43:57

标签: javascript php jquery html mysql

我是php新手。并在将要从mysql获取数据并在下拉列表中显示的位置编写此代码。选择并单击提交后,它将在其他下拉列表中显示其子级。当用户单击任何选项并按提交时,在最后一个节点上,将显示要插入到具有选定产品ID的数据库中的选项。我有3个父母,即电子产品,车辆,家具。我的所有代码对于电子设备而言都工作正常,但是在其余节点上却显示错误。即使我之前按下了单选按钮,它也会显示未定义的索引。单击提交后,单选按钮不会传递值。

我正在使用php7,Phpmyadmin。

        //calling parentids - - - - - - - - - - >
        $sql = "CALL `callcatname`()";
        $result = mysqli_query($conn, $sql);
        ?>
     <select name="select" style="width: 100px;"> 
     <?php
        if($result->num_rows > 0){
        while($row=mysqli_fetch_assoc($result)){
        echo "<option value=".$row["catname"].">".$row["catname"]."</option>";
        }
        } 
        $result->free();
        $conn->close;
        ?>
     <!-- calling parent id doneee (DB inactive) -->
     <!-- Calling categories -->
     <br>
     <div></div>
     <input type="Submit" value="Submit" name="Submit">
  </form>
  <?php 
     if(isset($_POST["Submit"])){
     ?>
  <table border=1>
     <th style="width:60px ">Select</th>
     <th>Name </th>
     <form action="index.php" method="Post">
        <?php
           $conn = mysqli_connect($servername, $username,$password,$database);
           $temp = $_POST["select"];
           setcookie("temp",$temp);
           $sql = "Call callchildren1('$temp')";
           $result = mysqli_query($conn,$sql);
           while($row=mysqli_fetch_assoc($result)){
           echo "<tr><td><input type='radio' value='".$row["ProdName"]."' name='".$temp."'></td><td>".$row["ProdName"]."</td></tr>";
           }
           $conn->close();
           $result->free();
           echo"<td><input type='Submit' name='Submit1' value='Submit'></td>";
           }
           ?>
  </table>
  </form>
  <!-- calling categories doneee (DB inactive) -->
  <!-- calling 3 level children -->
  <?php
     if(isset($_POST["Submit1"])){
     $conn = mysqli_connect($servername, $username,$password,$database);
     $temp = $_COOKIE["temp"];
     $cat = $_POST[$temp];
     Echo "<br><br>The products in <strong>".$temp."(".$cat.")</strong> are: <br><br> ";
     $sql = "Call callchildren1('$cat')";
     $result = mysqli_query($conn,$sql);
     ?>
  <form action="index.php" method="POST">
     <table border=1>
        <th style="width:80px">Select</th>
        <th>Name</th>
        <?php
           while($row=mysqli_fetch_assoc($result)){
           echo "<tr>
           <td><input type='radio' value='".$row["ProdName"]."' name='".$cat."'></td><td >".$row["ProdName"]."</td></tr>";
           setcookie("cat",$cat);
           }
           echo "<td style='padding-left:10px'><input type='submit' name='insert' value='Insert'></td>";
           // echo "<td style='padding-left:20px'><input type='submit' name='view' value='View'></td> </table>";
           $result->free();
           $conn->close();
           //setcookie('temp',"",time() -3000); 
           }
           ?>
  </form>
  </table>
  <?php
     $conn = mysqli_connect($servername, $username,$password,$database);
     if(isset($_POST["view"])){
     $cat1 = $_COOKIE["cat"];
     $sql = "Call callchildren1($cat1)";
     $result = mysqli_query($conn,$sql);
     echo $_POST[$cat1];;
     }
     ?>
  <?php
     $cat1 = $_COOKIE["cat"]; 

     if(isset($_POST["insert"])){

     $temp = $_POST[$cat1];
     echo"Product name: <input type='text' name='pname'> Product Category: <input type='text' name='pname' value='".$_POST[$cat1]."' disabled> <br><br> Product description:<input type='text' name='pname'> Product price:<input type='number' name='pname'>" ;
     echo"<br><br>Product image: <input type ='file' value='Upload Image' id='fileName' accept='.jpg' onchange='validateFileType'><br><br><input type='submit'>";

     }

     ?>
     </body>
     </html>

就像此屏幕截图中所示,SLR和DSLR是3级电子产品。如果我按提交,它将显示一个带有选定选项的文本框列表

Like in this screenshot the SLR and DSLR are 3 level children of electronics. and if i press submit it should show a list of text box with the selected option

enter image description here

即使我选择了一个单选按钮并按提交,它也会显示此错误

even if i select a radio button and press submit it shows this error

我希望结果会在文本框中显示所选选项。

0 个答案:

没有答案