'school',
'private' => 'private'
);
//This processes the page when it is submitted.
if (isset($_POST['submitted'])){
//errors array - check to see if the important fields were filled.
$errors = array();
if (empty($_POST['student_name'])){ $errors[] = "Please enter Student Name \n"; }
else { $student_name = $_POST['student_name']; }
if (empty($_POST['student_phone'])){ $errors[] = "Please enter Student Phone \n"; }
else { $student_phone = $_POST['student_phone']; }
//get the variables from the FORM POST.
//These come from this page earlier.
//See below the [if isset POST submitted] section.
$student_id = $_POST['student_id'];
$student_name = $_POST['student_name'];
$student_phone = $_POST['student_phone'];
$student_email = $_POST['student_email'];
if (empty($errors)){
require_once('mysql_connect.php');
//notice the quotes in the query
$query_students = "update students
set
student_name = \"$student_name\",
student_pw = \"$student_pw\",
student_category = \"$student_category\",
book = \"$book\",
where
domain_id = $domain_id
and teacher_id = $teacher_id
and student_id = $student_id
";
//this will display the query if you wish to see it while programming. Later you should hide it.
echo "
QStudents - ( $query_students )
";
//run the query
$result_students = @mysql_query($query_students);
//display the student name that was just added
if ($result_students){
echo "
Student $student_name was updated.
";
}
else {
echo "
Unable to update Student $student_name
";
}
}
else{ //report errors
echo "
Error!
The following errors occurred: ";
foreach ($errors as $msg){ echo "- $msg"; }
}
} // end if isset POST submitted
//This prepares the page & shows all the students, each with an edit button, ready for updates.
//start to write the html page
echo '
';
require_once ('mysql_connect.php');
$query = "select * from students order by student_name ";
//run the query
$result = @mysql_query($query);
if ($result){
echo '
Edit Students
';
while ($row = mysql_fetch_array($result,MYSQL_ASSOC)){
//includes two hidden inputs
echo "
";
}//end of while there are more rows
echo "
\n";
echo "
End of Student List
\n";
}
else{
echo '
Problem: Unable to retrieve data at this time.
';
} //end if query gave a result set
echo '';
mysql_close();
?>