加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
add_delete_sche.php 4.86 KB
一键复制 编辑 原始数据 按行查看 历史
little 提交于 2022-05-28 16:33 . 新增排班
<?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();
}
}
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化