Add Students

<?php session_name('StudentsRecords'); //session_start(); require_once('mysql_connect.php'); $domain_id = $_SESSION['domain_id']; $teacher_id = $_SESSION['teacher_id']; $category = array( 'student' => 'student', 'private' => 'private' ); echo ' <!DOCTYPE html PUBLIC "-//W#C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"/> <link rel="stylesheet" href="styles1.css" type="text/css" media="screen"> </head> <body> '; // prepare the next student_id $query = "select max(student_id) as student_id from students where domain_id = $domain_id and teacher_id = $teacher_id"; $result = @mysql_query($query); if ($result){ while ($row = mysql_fetch_array($result,MYSQL_ASSOC)){ $student_id = $row['student_id']; $student_id = $student_id + 1; } mysql_free_result($result); } else { echo "<h1>Problem: Unable to get next student_id number.<br>Try starting from login again.</h1>\n"; } echo "<h4>DID: $domain_id TID: $teacher_id NID:$student_id</h4>"; //check entered values if (isset($_POST['submitted'])){ //if (empty($_POST['student_id'])){$errors[] = 'Please enter StudentID';} else {$ri = $_POST['recid'];} //if (empty($_POST['teacher_id'])){$errors[] = 'Please enter Cantor name';} else {$ca = $_POST['teacher'];} $errors = array(); if (empty($_POST['student_name'])){$errors[] = "Please enter Student Name<br>\n";} else {$student_name = $_POST['student_name'];} if (empty($_POST['student_pw'])){$errors[] = "Please enter Student Password<br>\n";} else {$student_pw = $_POST['student_pw'];} $student_category = $_POST['student_category']; $book = 'book'; if (empty($errors)){ require_once('mysql_connect.php'); $query = "insert into students (domain_id,teacher_id,student_id,student_name,student_pw,student_category) values('$domain_id','$teacher_id','$student_id','$student_name','$student_pw','$student_category')"; $result = @mysql_query($query); if ($result){ echo "\n<h2>A new record was added for $student_name.</h2>\n"; } else { echo "\n<h2>Unable to add new record for student $student_name</h2>\n"; } require_once('mysql_connect.php'); $query = "insert into allusers (domain_id,user_id,user_name,user_pw,user_category) values('$domain_id','$student_id','$student_name','$student_pw','$student_category')"; $result = @mysql_query($query); if ($result){ echo "\n<h2>A new record was added for $student_name.</h2>\n"; } else { echo "\n<h2>Unable to add new record for student $student_name</h2>\n"; } } else{ //report errors echo "<h1>Error!</h1><br>"; foreach ($errors as $msg){echo "- $msg";} } } // end submitted // this code appears whether submitted already or not echo " <div> <h2>Add New Student</h2> <form method=\"POST\" action=\"teachers_add_students.php?".SID."\"> <input type=\"hidden\" name=\"submitted\" value=\"TRUE\" /> <table id=\"addstudent\" border=\"1\"> <tr> <td><h3>Student Name</h3><input type=\"text\" name=\"student_name\" /></td> <td><h3>Password</h3><input type=\"text\" name=\"student_pw\" /></td> <td><h3>Category</h3> <select name=\"student_category\"> "; foreach ($category as $key => $value){ echo "<option value=\"$key\">$value</option>\n"; } echo " </select> </td> </tr> <tr> <td colspan=\"3\" style=\"text-align:center;\"><input type=\"submit\" value=\"Add Student\" /></td> </tr> </table> </form> </div> </body> </html> "; mysql_close(); ?>