samedi 16 mai 2020

Undefined index: check_list on line 6 [duplicate]

Warning: Invalid argument supplied for foreach() in C:\wamp64\www\pop\orders.php on line 8 i am noob getting above mention 2 errors my table name is orders and column name is item_1 i want to insert multiple check boxes data into my database

here is code for me form multiple checkboxes

<div class="container">
        <form method="post" action="orders.php"> 


        <div class="list-group">
       <a href="#" class="list-group-item list-group-item-action"><button class="btn" data-toggle="collapse" data-target="#desi">DESI FOOD</button></a>
             <div id="desi" class="collapse" style="background-color: white;">
              <input type="checkbox" value="haleem" name=check_list[] /> Haleem <br>
              <input type="checkbox" value="chicken karahi" name=check_list[] /> Chicken Karahi <br>
              <input type="checkbox"  value="chanay paye" name=check_list[] /> Chanay Paye <br>
              <input type="checkbox" value="sabzi" name=check_list[] /> Sabzi <br>
            </div>
            <a href="#" class="list-group-item list-group-item-action"><button class="btn" data-toggle="collapse" data-target="#fast">FAST FOOD:</button></a>
             <div id="fast" class="collapse" style="background-color: white;">
              <input type="checkbox"  value="pizza"  name=check_list[] /> Pizza<br>
              <input type="checkbox"  value="burger"name=check_list[] /> Burger<br>
              <input type="checkbox"  value="pizza cone"name=check_list[] /> Pizza Cone <br>
              <input type="checkbox"  value="Shawarma" name=check_list[]/> Shawarma <br>
            </div>
            <a href="#" class="list-group-item list-group-item-action"><button class="btn" data-toggle="collapse" data-target="#drink">DRINKS</button></a>
             <div id="drink" class="collapse" style="background-color: white;" >
              <input type="checkbox" value="coca cola"  name=check_list[]/> Coca Cola<br>
              <input type="checkbox"  value="Red Bull" name=check_list[]/> Red Bull <br>
              <input type="checkbox" value="Orange juice" name=check_list[] /> Orange Juice <br>
              <input type="checkbox"  value="Lemon Juice" name=check_list[]/> Lemon Juice <br>
            </div>
        </div>
        <br>

     <button type="submit"   class="btn-success" style=" display: flex; margin:0 auto; align-items:center;">Order</button>
       </form>
    </div>

and here is code for my orders.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$db = "hotel";
$checkbox1 = $_POST['check_list'];
  $chk="";  
    foreach($checkbox1 as $chk1)  
       {  
          $chk.= $chk1.",";  
       }  
// Create connection
$conn = mysqli_connect($servername, $username, $password,$db);
// Check connection
if (!$conn) {
   die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
$sql = "INSERT INTO orders(item_1)VALUES( '$chk' )";

if(mysqli_query($conn,$sql)) {

    echo 'Data added sucessfully';
} 

?>



Aucun commentaire:

Enregistrer un commentaire