代码拉取完成,页面将自动刷新
<?php
// check the input 管理对排班信息的增删
function check($value)
{
if (get_magic_quotes_gpc()) {
$value = htmlspecialchars(trim($value));
} else {
$value = addslashes(htmlspecialchars(trim($value)));
}
return $value;
}
session_start();
if (!isset($_SESSION['username']) or !isset($_SESSION['identity']) or $_SESSION['identity'] != 2) {
header("Location:login.php");
exit();
}
$Sno = check($_POST['Sno']);
$Dno = check($_POST['Dno']);
$StartTime = check($_POST['StartTime']);
$AppointedOrNot = check($_POST['AppointedOrNot']);
$operation = $_POST['operation_choice'];
if ($operation == 1) { // insert
if ($Sno == "" || $StartTime == "" || $Dno == "" || $AppointedOrNot == "") {
echo "
<script>
alert('排班信息不能为空!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
} else {
$db = @mysqli_connect("localhost", "root", "123456", "MIS");
if (!$db) {
die("Fail to connect the database!!" . mysqli_connect_error());
}
mysqli_query($db, "begin");
mysqli_query($db, "set names utf8");
$check_Sno = mysqli_query($db, "SELECT * FROM Schedule WHERE Sno='$Sno' for update");
if (mysqli_fetch_array($check_Sno)) { //fetch_array
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('排班号已存在!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
} else {
$check_username = mysqli_query($db, "SELECT * from Doctor WHERE Dno='$Dno'");
if (!$check_username) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('该医生不存在!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
}
//else {
// $name = mysqli_fetch_array($check_username)['Dname'];
// }
$result = mysqli_query($db, "INSERT INTO Schedule(Sno, StartTime, AppointedOrNot, Dno) VALUES ('$Sno', '$StartTime', '$AppointedOrNot', '$Dno')");
if ($result) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('添加排班成功!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
} else {
echo '添加失败!!', mysqli_error($db), '<br />';
echo 'Click here to <a href="javascript:history.back(-1);">go back</a> and retry..';
mysqli_query($db, "rollback");
mysqli_close($db);
exit();
}
}
}
} elseif ($operation == -1) { // delete
if ($Sno == "") {
echo "
<script>
alert('排班号不能为空!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
} else {
$db = @mysqli_connect("localhost", "root", "123456", "MIS");
if (!$db) {
die("Fail to connect the database!!" . mysqli_connect_error());
}
mysqli_query($db, "begin");
mysqli_query($db, "set names utf8");
$check_Sno = mysqli_query($db, "SELECT * FROM Schedule WHERE Sno='$Sno' for update");
if (mysqli_fetch_array($check_Sno)) {
$result = mysqli_query($db, "DELETE FROM Schedule WHERE Sno='$Sno'");
if ($result) {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('删除排班成功!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
} else {
echo '删除失败!!', mysqli_error($db), '<br />';
echo 'Click here to <a href="javascript:history.back(-1);">go back</a> and retry..';
mysqli_query($db, "rollback");
mysqli_close($db);
exit();
}
} else {
mysqli_query($db, "commit");
mysqli_close($db);
echo "
<script>
alert('排班号不存在!!');
window.location.href = 'admin_schedule.php';
</script>
";
exit();
}
}
}
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。