如何在php mysql中将多行数据插入多行

I have retrieved data from the table and all the retrieved data to be stored in another table in each row. I have tried the below code but it is inserting only "

$roll_no = $_POST['roll_no'];
$name = $_POST['name'];
$class = $_POST['class'];
$section =  $_POST['section'];
$m_am = $_POST['m_am'];
$a_pm = $_POST['a_pm'];
$date = $_POST['date'];
echo $a_pm .'<br>'.$m_am.'<br>'.$roll_no;

/*$sql_2 = mysql_query("INSERT INTO stud_class_attendance (`sca_rollno`, `sca_name`, `sca_class`, `sca_section`,`sca_am`, `sca_pm`,                     
?>"

Use mysqli instead of mysql to prevent hacking and also validate the user input use htmlentities() or htmlspecialchars()

<?php
$roll_no = htmlspecialchars($_POST['roll_no']);
$name = htmlspecialchars($_POST['name']);
$class = htmlspecialchars($_POST['class']);
$section =  htmlspecialchars($_POST['section']);
$m_am = htmlspecialchars($_POST['m_am']);
$a_pm = htmlspecialchars($_POST['a_pm']);
$date = htmlspecialchars($_POST['date']);
echo $a_pm .'<br>'.$m_am.'<br>'.$roll_no;

$sql_2 = mysqli_query("INSERT INTO stud_class_attendance (`sca_rollno`, `sca_name`, `sca_class`, `sca_section`,`sca_am`, `sca_pm`, `date`) 
values ('$roll_no','$name','$class','$section','$m_am','$a_pm','$date');
$sql_2->execute();
?>
  1. You need a loop for that..
  2. Execute your first query. get all the records from the first query. iterate them and insert one by one in database

See the example

     $select = mysql_query("SELECT 
              name,rollno,class,section,a_am,a_pm,`date` 
              FROM `student`");
        // check if event 1 row exists in database
           if(mysql_num_rows($select) > 0 ){
            // while loop to iterate every row one by one 
            $count =0;
                while ($row = mysql_fetch_assoc($select)) {
                        $insert = mysql_query("INSERT INTO `stud_class_attendance`
                       (`sca_rollno`, `sca_name`, `sca_class`, `sca_section`,`sca_am`, `sca_pm`) 
                       VALUES
                       ('".$row['rollno']."','".$row['name']."','".$row['class']."',
                     '".$row['section']."','".$row['a_am']."','".$row['a_pm']."')");
                      // check if the query was executed 
                    if(mysql_insert_id() > 0){
                        $count++;
                    }
               }
        }
    echo $count." rows inserted";
$sql='
    INSERT INTO `stud_class_attendance` (
        `sca_rollno`, `sca_name`,`sca_class`, `sca_section`,`sca_am`, `sca_pm`
    ) 
    SELECT rollno,name,class,section,a_am,a_pm FROM `student`
';

$sql2=mysqli_query($sql);
$sql2->execute();