Insert multiple rows into a MySQL database from a table

后端 未结 1 1794
耶瑟儿~
耶瑟儿~ 2021-01-24 03:09

I retrieve data from databased based on 4 dropdown criteria.Display them on a table and add one column for scores of each student. I want to populate another table with all the

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-24 03:32

    I have found an answer to the question: Just declare the name field as an array and insert them into the DB using foreach loop.

    while($fetch=mysqli_fetch_array($confirm)){
            $c++;
        echo "";
        echo "".$c."";
        echo"";
        echo"";
        echo"";
        echo"";
        echo"";
        echo"";
        echo "";
        echo "";
        echo "";   
        }
      //if score is  supplied , then click to save to database
         }
       if(isset($_POST["saveBtn"])){
    
           foreach($_POST["admNo"] as $rec=> $value){
             $cl = $_POST["class"][$rec];
             $term = $_POST["Term"][$rec];
             $ad = $_POST["admNo"][$rec];
             $Csess = $_POST["SessionAssigned"][$rec];
             $sub = $_POST["sub"][$rec];
             $sc = $_POST["score"][$rec];  
    
      $insert = "INSERT INTO result_tab(CSession,Term,Class,AdmNo,subject,score)VALUES('$Csess','$term',
                    '$cl','$ad','$sub','$sc')";
     $succ = mysqli_query($connection,$insert); 
           }
    
         }
    

    0 讨论(0)
提交回复
热议问题