i want to insert data from a form which is declared in while loop and can be iterated 40 times (mean 40 row with 6 input fields each row).so what i need,i need to insert data from every input field (currently 6) to mysql row .so how can i accomplish that.please ask me for further detail if you need.
looking forward for best answer.i am stuck here and it's my degree final year project. thank you for help.
This is while loop with input fields code and name retrieved from database.
include'connection.php';
$res=mysql_query("SELECT * FROM `std_register` AS p1 ,`sims-register-course` AS p2 WHERE p2.semester=p1.std_semester and p2.department=p1.std_department and p2.id = '".$_GET['id']."'");
if ($res==FALSE) {
echo die(mysql_error());
}
echo "<form method='POST' action= '".htmlspecialchars($_SERVER['PHP_SELF'])."'.'>'";
while ($row=mysql_fetch_assoc($res)) {
echo "<tr>";
echo "<td>".$row["std_name"].'</td>';
echo "<td><input type='text' id='attendence_marks' name='attendence_marks[]' class='input-field-size'></td>";
echo "<td><input type='text' id='assignment_marks' name='assignment_marks[]' class='input-field-size'></td>";
echo "<td><input type='text' id='presentation_marks' name='presentation_marks[]' class='input-field-size'></td>";
echo "<td><input type='text' id='other_marks' name='other_marks[]' class='input-field-size'></td>";
cho "<td><input type='text' id='mid_marks' name='mid_marks[]' class='input-field-size'></td>";
echo "<td><input type='text' id='final_marks' name='final_marks[]' class='input-field-size'></td>";
}
I want to insert data from this form to database with single button click after fields are filled.and input all the rows of form into database at once.
This is the loop i have used to insert data but not working and display me some errors also.previously i have used for loop but that was also not working correctly.and insert only 0's to database.please checkout the loop code here and i think i am doing it wrong so please make me correct.
<?php
$count = count($_POST);
echo "count is :".$count ."<br>";
if(isset($_POST['submit'])) {
$attendence_marks=$_POST['attendence_marks'];
$assignment_marks=$_POST['assignment_marks'];
$presentation_marks=$_POST['presentation_marks'];
$other_marks=$_POST['other_marks'];
$mid_marks=$_POST['mid_marks'];
$final_marks=$_POST['final_marks'];
$total_marks = $attendence_marks+$assignment_marks+$presentation_marks+$other_marks+$mid_marks+$final_marks;
foreach ($attendence_marks as $key1 => $att_marks) {
foreach ($assignment_marks as $key2 => $assig_marks) {
foreach ($presentation_marks as $key3 => $pre_marks) {
foreach ($other_marks as $key4 => $o_marks) {
foreach ($mid_marks as $key5 => $m_marks) {
foreach ($final_marks as $key6 => $f_marks) {
foreach ($total_marks as $key7 => $t_marks) {
$i = "INSERT INTO `std_gradding` (attendence_marks,assignment_marks,presentation_marks,other_marks,mid_term_marks,final_marks,total_marks) VALUES ('$att_marks','$assig_marks','$pre_marks','$o_marks','$m_marks','$f_marks','$t_marks')";
$result = mysql_query($i) or die(mysql_error());
echo "Data Inserted.Thank you.";
echo "$assignment_marks , $presentation_marks , $other_marks , $mid_marks , $final_marks , $total_marks" ;
}
}
}
}
}
}
}
}
?>