$numbers = array('Age', 'offhours', 'onhours', 'HasPhoto', 'HasCert', 'HasEvalForm', 'schoolyear', 'semester'); $bools = array('HasPhoto' => 'rp', 'HasCert' => 'rc', 'HasEvalForm' => 're'); foreach ($_POST as $key => $value) { if ($key == 'sid' || $key == 'onid' || $key == 'offid') { ctype_digit($value) or die('Error: record does not exist.'); $id = $value; $col = $db->escape($key); } else { $key = in_array($key, $bools) ? array_search($key, $bools) : $db->escape($key); $value = $key === 'Bday' ? date('Y-m-d', strtotime(trim($value))) : $db->escape($value); if (strstr($key, '-') === false) { $value = in_array($key, $numbers) ? $value : "'{$value}'"; $sql = "UPDATE students SET {$key} = {$value} WHERE {$col} = {$id}"; } else { $arrkey = explode('-', $key); $value = in_array($arrkey[1], $numbers) ? "{$value}" : "'{$value}'"; if (empty($col)) { $sql = "UPDATE {$arrkey['0']} SET {$arrkey['1']} = {$value}"; } else { $sql = "UPDATE {$arrkey['0']} SET {$arrkey['1']} = {$value} WHERE {$col} = {$id}"; } } echo "{$sql}. "; if ($db->query($sql) && $db->getAffected() > 0) { echo "Saved."; } else { echo $db->getError(); } } } }
} else { if (isset($_POST['deleval'])) { $id = intval($_POST['deleval']); $sql = "DELETE FROM evaluation WHERE id = {$id}"; if ($db->query($sql)) { echo 'Record deleted.'; } else { die('Error: ' . $db->getError()); } } else { if (isset($_POST['delact'])) { $actid = intval($_POST['delact']); $type = $db->escape($_POST['type']); $id = strstr($type, 'campus', true); $sql = "DELETE FROM {$type} WHERE {$id}id = {$actid}"; if ($db->query($sql) && $db->getAffected() > 0) { echo "Record deleted!"; } else { die('Error: Record does not exist.'); } } else { if (isset($_POST['delstud'])) { $student = intval($_POST['delstud']); $find = array('oncampus' => 'onid', 'offcampus' => 'offid'); foreach ($find as $key => &$value) { $value = array($value); $sql = "SELECT {$value['0']} FROM {$key} WHERE student = {$student}"; if (($result = $db->query($sql)) && $db->getAffected() > 0) { while ($row = mysqli_fetch_assoc($result)) { $value[] = $row[$value[0]]; }