$query = mysql_query("SELECT parentid FROM parents WHERE userid='{$_POST['username']}'") or die("Unable to get the newly entered parentid - " . mysql_error());
        $parentid = mysql_result($query, 0);
        // Also insert the "registered" grouping of parent and student //
        $query = mysql_query("INSERT INTO parent_student_match (parentid, studentid) VALUES( '{$parentid}', '{$_POST['student']}')") or die("ManageParents.php: Unable to insert the parent to student match - " . mysql_error());
    }
}
// Edit the parent if one is being edited //
if ($_POST["editparent"] == 1 && $_POST["username"] != "" && $_POST["fname"] != "" && $_POST["lname"] != "" && $_POST["student"] != "") {
    $query = mysql_query("UPDATE `parents` SET `userid`='{$_POST['username']}', `fname`='{$_POST['fname']}', `lname`='{$_POST['lname']}' WHERE `parentid`='{$_POST['parentid']}' LIMIT 1") or die("ManageParents.php: Unable to update the parent information - " . mysql_error());
}
// Delete the parent(s) that the parent has requested as well as the classes belonging to those parents //
if ($_POST["deleteparent"] == 1) {
    require_once "DeleteFunctions.php";
    $delete = $_POST["delete"];
    for ($i = 0; $i < sizeof($delete); $i++) {
        deleteParent($delete[$i]);
    }
}
print "<script language='JavaScript'>\n\n  // Function to make sure the parent wants to delete the parent(s) //\n  function validate()\n  {\n   if( document.parents.selectparent.value > 0 )\n   {\n\tvar confirmed = confirm(\"Are you sure you want to delete this parent?\");\n\n\tif( confirmed == true )\n\t{\n\t document.parents.submit();\n\t}\n   }\n   else\n   {\n\talert('You must select a parent to delete.');\n   }\n  }\n\n\n  // Function to make sure only one checkbox has been selected //\n  function checkboxes()\n  {\n   if( document.parents.selectparent.value == 1 )\n   {\n\tdocument.parents.submit();\n   }\n   else\n   {\n\tif( document.parents.selectparent.value > 1 )\n\t{\n\t alert('You can only edit one parent at a time.');\n\t}\n\telse\n\t{\n\t alert('You must select a parent to edit.');\n\t}\n   }\n  }\n\n\n  // Function to keep track of how many checkboxes are checked //\n  function updateboxes(row)\n  {\n   row = row + 2;\n\n   if(document.parents.elements[row].checked)\n   {\n\tdocument.parents.selectparent.value = Math.round(document.parents.selectparent.value) + 1;\n   }\n   else\n   {\n\tdocument.parents.selectparent.value = Math.round(document.parents.selectparent.value) - 1;\n   }\n  }\n </script>\n\n <h1>Manage Parents</h1>\n <br><br>\n <table align='center' width='500' cellspacing='0' cellpadding='0' border='0'>\n <tr>\n <td>\n <form name='parents' action='./index.php' method='POST'>\n  <input type='button' value='Add' onClick='document.parents.page2.value=23;document.parents.submit();'>\n  <input type='button' value='Edit' onClick='document.parents.page2.value=24;checkboxes();'>\n  <input type='button' value='Delete' onClick='document.parents.deleteparent.value=1;validate();'>\n  <br><br>\n  <table cellspacing='0' width='500' cellpadding='8' class='dynamiclist'>\n   <tr class='header'>\n\t<td>&nbsp;</td>\n\t<th>First Name</th>\n\t<th>Last Name</th>\n\t<th>Student Name</th>\n\t<th>Username</th>\n   </tr>";
// Get the total number of parents to know how many pages to have //
$query = mysql_query("SELECT COUNT(*) FROM parents") or die("ManageParents.php: Unable to retrieve total number of parents - " . mysql_error());
$numrows = mysql_result($query, 0);
$numpages = ceil($numrows / 25);
if ($_POST["onpage"] == "") {
    $_POST["onpage"] = 1;
}
// Get and display the parents //
$query = mysql_query("SELECT p.parentid,p.fname,p.lname,u.username FROM parents p, users u WHERE p.userid = u.userid") or die("ManageParents.php: Unable to get a list of parents - " . mysql_error());
$row = 0;
$actualrow = 0;
while ($parent = mysql_fetch_row($query)) {
function deleteUser($userid)
{
    $query = mysql_query("SELECT type FROM users WHERE userid = {$userid}");
    $type = @mysql_result($query, 0);
    $query = mysql_query("DELETE FROM users WHERE userid = {$userid} LIMIT 1") or die("DeleteFunction.php: Unable to delete selected User(s) - " . mysql_error());
    switch ($type) {
        case "Teacher":
            // Get the list of teachers/substitutes that will also be deleted and delete them //
            $query = mysql_query("SELECT teacherid FROM teachers WHERE userid = {$userid}") or die("DeleteFunctions.php: Unable to get list of teachers to delete for deleteUser() - " . mysql_error());
            while ($teacherid = mysql_fetch_row($query)) {
                deleteTeacher($teacherid[0]);
            }
            break;
        case "Student":
            // Get the list of students that will also be deleted and delete them //
            $query = mysql_query("SELECT studentid FROM students WHERE userid = {$userid}") or die("DeleteFunctions.php: Unable to get list of students to delete for deleteUser() - " . mysql_error());
            while ($studentid = @mysql_result($query, 0)) {
                deleteStudent($studentid);
            }
            break;
        case "Parent":
            // Get the list of parents that will also be deleted and delete them //
            $query = mysql_query("SELECT parentid FROM parents WHERE userid = {$userid}") or die("DeleteFunctions.php: Unable to get list of parents to delete for deleteUser() - " . mysql_error());
            while ($parentid = @mysql_result($query, 0)) {
                deleteParent($parentid);
            }
            break;
        case "Admin":
            // Get the list of administration staff that will also be deleted and delete them //
            $query = mysql_query("SELECT adminid FROM adminstaff WHERE userid = {$userid}") or die("DeleteFunctions.php: Unable to get list of admins to delete for deleteUser() - " . mysql_error());
            while ($adminid = @mysql_result($query, 0)) {
                deleteAdmin($adminid);
            }
            break;
    }
}