0

I want to insert row with values which is shown in the foreach loop, in a table names as exams_record using php.

So, How can I insert the values I am printing in foreach into table exams_record?

<?php

$db_exams = mysqli_connect('localhost','root','','exams');

$sql_query = "SELECT * FROM exam_timing AS et INNER JOIN exam_details AS ed
  ON et.exam_id = ed.Id WHERE et.Admin_Id = '$username'";
$ids = mysqli_fetch_all(mysqli_query($db_exams, $sql_query), MYSQLI_ASSOC);


foreach($ids as $id) {
  echo $id['id']," ",$id['exam_id']," ",$id['time']," ",$id['date']," ",$id['timeduration'],
  " ",$id['max_score']," ",$id['Admin_Id']," ",$id['Id']," ",$id['Name']," ",$id['Course']," ",
  $id['Semester']," ",$id['Year'],"<br>";
}

?>

<html>
    <body>
        <div id ="exams_container">
            <table id="exams_record">
                <colgroup>
                    <col span="1" style="width: 80%;">
                    <col span="6" style="width: 10%;">
                </colgroup>
                <tr>
                    <th>Today's Exam</th>
                    <th>Course</th>
                    <th>Timing</th>
                    <th>Date</th>
                    <th>Year</th>
                    <th>Semester</th>
                    <th>Preview</th>
                </tr>
            </table>
        </div>
    </body>
</html>
azibom
  • 1,580
  • 1
  • 5
  • 20
Pawan bisht
  • 159
  • 1
  • 8
  • 2
    There is no question here – John Conde Dec 25 '20 at 14:20
  • Question is how i can insert values from a database into the table exam records in php? – Pawan bisht Dec 25 '20 at 14:24
  • https://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php? – VirCom Dec 25 '20 at 14:25
  • 3
    Do not use string interpolation or concatenation to get values into SQL queries. That's error prone and might make your program vulnerable to SQL injection attacks. Use parameterized queries. See ["How to include a PHP variable inside a MySQL statement"](https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement) and ["How can I prevent SQL injection in PHP?"](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). – sticky bit Dec 25 '20 at 14:40

0 Answers0