Edit Students

<?php session_name('StudentsRecords'); session_start(); //assign vars from the session vars $domain_id = $_SESSION['domain_id']; $teacher_id = $_SESSION['teacher_id']; //an array (which we won’t actually use here) $category = array( 'student' => '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<br>\n"; } else { $student_name = $_POST['student_name']; } if (empty($_POST['student_phone'])){ $errors[] = "Please enter Student Phone<br>\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 "<p>QStudents - ( $query_students ) </p> "; //run the query $result_students = @mysql_query($query_students); //display the student name that was just added if ($result_students){ echo "<p>Student $student_name was updated.</p>"; } else { echo "<p>Unable to update Student $student_name</p>"; } } else{ //report errors echo "<h1>Error!</h1>The following errors occurred:<br>"; 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 ' <html> <head> <link rel="stylesheet" href="styles1.css" type="text/css" media = "screen"> </head> <body> '; require_once ('mysql_connect.php'); $query = "select * from students order by student_name "; //run the query $result = @mysql_query($query); if ($result){ echo '<div><h2>Edit Students</h2>'; while ($row = mysql_fetch_array($result,MYSQL_ASSOC)){ //includes two hidden inputs echo " <form method=\"POST\" action=\"teachers_edit_students.php?".SID."\"> <input type=\"hidden\" name=\"submitted\" value=\"TRUE\"> <input type=\"hidden\" name=\"student_id\" value=\" " . $row['student_id'] . " \"> <input name=\"student_name\" value=\" " . $row['student_name'] . " \"> <input name=\"student_phone\" value=\" " . $row['student_phone'] . " \"> <input name=\"student_email\" value=\" " . $row['student_email'] . " \"> <input type=\"submit\" value=\"Save\"> </form> "; }//end of while there are more rows echo "</div>\n"; echo "<h2>End of Student List</h2></div>\n"; } else{ echo '<h2>Problem: Unable to retrieve data at this time.</h2>'; } //end if query gave a result set echo '</body></html>'; mysql_close(); ?>