I am doing an insert into a database in php so that it submits more than one row as the information to be submitted is dynamically generated.problem is that it only submits the last data and ignores the rest.how do i do it?here is my code:
<?php
include('includes/conn.php');
$row="SELECT name,refNo,department FROM profile WHERE department='$getid'";
$query=mysqli_query($conn,$row) or die(mysqli_error($conn));
echo "<div class='col-md-4 col-md-offset-1' >";
echo "<table class='table table-hover table-striped table-bordered'>
<tr class='info'>
</tr>";
while($row=mysqli_fetch_array($query))
{
$name=$row['name'];
$job=$row['refNo'];
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['refNo']."</td>";
echo "<form method='post' action='selection.php'>";
echo "<td>"."<input type='text' name='essential' class='form-control' width='100%' required>"."</td>";
echo "<td>"."<input type='text' name='desirable' class='form-control' width='100%' required>"."</td>";
echo "<input type='hidden' name='name' value='".$name."'>";
echo "<input type='hidden' name='job' value='".$job."'>";
echo "</tr>";
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$job=$_POST['job'];
$essential=$_POST['essential'];
$desirable=$_POST['desirable'];
$insert="INSERT INTO shortlist(name,job,points) VALUES('$name','$job','$essential' + '$desirable')";
$query=mysqli_query($conn,$insert) or die(mysqli_error($conn));
if($query)
{
header("location:index.php");
}
}
}
echo "</table>";
echo "<input type='submit' class='btn btn-success' name='submit' value='Submit'>";
"</form>";
echo "</div>";
mysqli_close($conn);
?>