Ok I have been working on this for a long time and I am just plain stuck. What I am developing is an online application for a school to keep track of missing assignments that students have. I have a table that lists the students first name, last name, homeroom, and last period teachers. Each student in the table has an ID. What I want to do is have teachers click on "Add Assignment" and they would enter the assignment details and the subject and then using checkboxes select the students that are missing such assignment. Then on "Submit" the student data (first name, last name, homeroom, and last period teachers) would get copied into a new table along with the description of the assignment and the subject each as their own ID. This is so the teacher only has to enter the description and the subject once, but can assign it to multiple students.
I have two tables in a database "student" and "assignments" Inside the "student" table I have 4 fields (firstName, lastName, AP, and 8th) and in the "assignments" table I have 6 fields (firstName, lastName, AP, 8th, description, and subject). If you can help please do. I have looked everywhere on the internet for some examples to work off of, but I cannot find anything. I find lots on deleting multiple rows by clicking check boxes but that is not helping me.
Here is my code:
<?php
//Database Connection
mysql_connect($_MISSING['db_host'], $_MISSING['db_username'], $_MISSING['db_password']) or die(mysql_error());
@mysql_select_db($_MISSING['db_database']) or die(mysql_error());
if (!$user_id) include("login.php");
print("<title>" . $_MISSING['organization'] . " - " . $_MISSING['html_title'] . " / Add Assignment");
print("<link rel=\"stylesheet\" href=\"../css/style.css\" title=\"style.css\" type=\"text/css\">");
$sql="SELECT * FROM student ORDER BY lastName";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<?php
print("<p>Enter New Assignment</p>");
print("<p><b>Subject:</b> <input type=\"text\" name=\"subject\" size=\"50\" /></p>");
print("<p><b>Description:</b> <input type=\"text\" name=\"description\" size=\"100\" /></p>");
//Prints Student in a Table
print("<div class=\"student_wrapper\">");
print("<div class=\"student_checkbox\">");
print("<b>ID</b>");
print("</div>"); //Closes DIV student_checkbox
print("<div class=\"student_lastName\">");
print("<b>Last Name</b>");
print("</div>"); //Closes DIV student_lastname
print("<div class=\"student_firstName\">");
print("<b>First Name</b>");
print("</div>");//Closes DIV student_firstname
print("<div class=\"student_AP\">");
print("<b>AP</b>");
print("</div>");//Closes DIV student_AP
print("<div class=\"student_8th\">");
print("<b>8th</b>");
print("</div>");//Closes DIV student_8th
print("<br /><hr />");
while($students = mysql_fetch_array($result))
{
$value = ($students['id']);
?>
<div class="student_checkbox"><input class="checkbox" name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $value; ?>"></div>
<?PHP
print("<div class=\"student_lastName\">" . $students['lastName'] . "</div>");
print("<div class=\"student_firstName\">" . $students['firstName'] . "</div>");
print("<div class=\"student_AP\">" . $students['AP'] . "</div>");
print("<div class=\"student_8th\">" . $students['8th'] . "</div>");
print("<br>");
}
print("</div>"); //End of <DIV class="student_wrapper">
print("<input type=\"submit\" name=\"submit\" value=\"Submit\" />");
print("</form>");
// Check if add button active, start this
if($_POST['submit']){
$checkbox=$_POST['checkbox'];
for($i=0;$i<$count;$i++){
$ID = $checkbox[$i];
$first = $students['firstName'];
$last = $students['lastName'];
$AP_teacher = $students['AP'];
$last_teacher = $students['8th'];
$description = $_POST['description'];
$subject = $_POST['subject'];
$sql = "INSERT INTO assignments SET id = '$ID', firstName = '$first', lastName = '$last', AP = '$AP_teacher', 8th = '$last_teacher', description = '$description', subject = '$subject'";
$result = mysql_query($sql) or die(mysql_error());
}
// if successful redirect back to main page.
if ($result) {
echo('<p>New assignments added</p>');
echo '<META HTTP-EQUIV="Refresh" Content="5; URL=../index.php">';
exit;
} else {
echo('<p>Error adding new assignment: ' . mysql_error() . '</p>');
}
}
mysql_close();
?>