Hello,
I want to submit multiple records into a mysql database, and I have hit a snag.
I am developing a web application that displays student records, and upon displaying student records per class, I want to be able to add marks for beginning of term, mid term and end of term.
The problem is that, since I am not sure of how many rows of records the sql statement will return, I can't declare different variables for each student mark.
I tried using the foreach loop but it kept showing me an error in declaration of variables. The loop is is;
<?php
$class = $_POST['class_name'];
$subject = $_POST['subject'];
$term = $_POST['term'];
$search_year = $_POST['search_year'];
if($_POST['add_marks'] ==1)
{
include('includes/connect.php');
foreach($_POST['bot'] as $bot && $_POST['mt'] as $mt && $_POST['eot'] as $eot)
{
$insert = ""INSERT INTO marks(beginning_of_term,mid_term,end_of_term) VALUES($bot,$mt,$eot);
$execute_insert = mysql_query($insert);
}
}
?>
Here is the code that I am working with to display the records from the database; then insert marks as per the student record returned;
<?php
include('includes/connect.php');
// select record from mysql
$sql="SELECT DISTINCT * FROM students WHERE school_id='$sch_id' AND class='$class'";
$result=mysql_query($sql);
if(mysql_num_rows($result) == 0){ echo "<font color='red' size='3'>No Registered Students yet</font> <a href='teacher_home.php?page=new_student&Id=$sch_id'>Add Student";
}
else
{
echo "<table width='850' border='0'>
<tr style='font-size: 12px; font-weight: bold; color: rgb(0, 153, 204); background: none repeat scroll 0% 0% rgb(230, 249, 217);'>
<td width='400'>Student</td>
<td width='200'>Reg No</td>
<td width='130'>Class</td>
<td width='150'><div align='center'>Beginning of Term</div></td>
<td width='150'><div align='center'>Mid Term</div></td>
<td width='150'><div align='center'>End of Term</div></td>
</tr>";
?>
<?php
$num=1;
while($rows=mysql_fetch_array($result)){
$num++;
$skizzy = $rows['school_id'];
if(($num%2)!=0){
$bg="#FFFF99";
}else{
$bg="#FFFFFF";
}
?>
<tr bgcolor="<?php echo $bg; ?>">
<td><?php echo $rows['firstName']." ".$rows['lastName']." ".$rows['otherName']; ?></td>
<td><?php echo $rows['regNo']; ?></td>
<td><?php echo $rows['class']." ".$rows['stream']; ?></td>
<td><div align="center"><input type="text" name="bot" size="10" /></div></td>
<td><div align="center"><input type="text" name="mt" size="10" /></div></td>
<td><div align="center"><input type="text" name="eot" size="10" />
</div></td>
</tr>
<?php
}
}
?>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><div align="center"><input type="image" name="submit" id="submit" value="Submit" style="border:none" src="image/submit.jpg" /> <input type="hidden" name="add_marks" value="1" /></div></td>
<td><div align="center"> </div></td>
<td><div align="center">
</div></td>
</tr>
</table>
THANKS IN ADVANCE