what should i write the foreach loop
if this is the form..
<form name="form1" id="form1" method="post" action="masuk_markah_pelajar.php">
<table width="91%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="16%"><div align="center">CODE </div></td>
<td width="50%"><div align="left">SUBJECT</div></td>
<td width="21%">MARK</td>
<td width="13%">GRED</td>
</tr>
<?php do { ?>
<tr>
<td><div align="center"><?php echo $row_subject['CODE_SUBJ']; ?></div></td>
<td><div align="left"><?php echo $row_subject['NAME_SUBJECT']; ?></div></td>
<td><input name="mark[]" type="text" size="3" maxlength="3" />
%</td>
<td><select name="gred[]">
<option selected value="">Select</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select></td>
</tr>
<?php } while ($row_subject = mysql_fetch_assoc($subject)); ?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input name="id" type="hidden" value="<? echo $_GET['idstudent'];?>" />
<input name="sem" type="hidden" value="<? echo $_GET['semester'];?>" />
<input name="year" type="hidden" value="<? echo $_GET['year'];?>" />
<input name="code[]" type="hidden" value="<?php echo $row_subject['CODE_SUBJ']; ?>" />
<input name="subject[]" type="hidden" value="<?php echo $row_subject['NAME_SUBJECT']; ?>" /> <input name="Send" type="submit" class="button" id="Send" value="Send" /></td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
and this is form action..
<?
include 'db_connect.php';
// build the form action
if($_POST['Send'] == "Send"){
$id = $_POST['id'];
$jenis = $_POST['sem'];
$tahun = $_POST['year'];
if(is_array($_POST['mark'])){
foreach($_POST['mark'] as $mark){
if(is_array($_POST['gred'])){
foreach($_POST['gred'] as $gred ) {
if(is_array($_POST['code'])){
foreach($_POST['code'] as $code) {
if(is_array($_POST['subject'])){
foreach($_POST['subject'] as $subject){
$sql = mysql_query("INSERT INTO result (id_stud, sem, year, mark, gred, subject_code, name_subject)
VALUES ('$id', '$sem', '$year', '$mark', '$gred', '$code', '$subject')");
}
}
}
}
}
}
}
}
if ($sql) {
include 'page.php';
exit();
} else {
echo mysql_error();
}
}
?>
this form action insert so many data in my database...
please help me to fix it...