first commit
This commit is contained in:
72
patient_90.php
Normal file
72
patient_90.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require 'db_config.php';
|
||||
$conn = $link;
|
||||
mysqli_set_charset($link, 'utf8');
|
||||
// 初始化变量
|
||||
$patient_id = $patient_name = $patient_gender = $patient_address = "";
|
||||
|
||||
// 检查表单提交
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$patient_id = ($_POST['patient_id']);
|
||||
$patient_name = ($_POST['patient_name']);
|
||||
$patient_gender = ($_POST['patient_gender']);
|
||||
$patient_address = ($_POST['patient_address']);
|
||||
|
||||
// 保存数据
|
||||
try {
|
||||
// 检查是否存在该患者
|
||||
$query = "SELECT COUNT(*) AS count FROM patient_90 WHERE patient_id = '$patient_id'";
|
||||
$result = mysqli_query($conn, $query);
|
||||
$row = mysqli_fetch_assoc($result);
|
||||
|
||||
if ($row['count'] > 0) {
|
||||
// 更新记录
|
||||
$update_query = "UPDATE patient_90 SET
|
||||
patient_name = '$patient_name',
|
||||
patient_gender = '$patient_gender',
|
||||
patient_address = '$patient_address'
|
||||
WHERE patient_id = '$patient_id'";
|
||||
mysqli_query($conn, $update_query);
|
||||
} else {
|
||||
// 插入新记录
|
||||
$insert_query = "INSERT INTO patient_90
|
||||
(patient_id, patient_name, patient_gender, patient_address)
|
||||
VALUES
|
||||
('$patient_id', '$patient_name', '$patient_gender', '$patient_address')";
|
||||
mysqli_query($conn, $insert_query);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
die("数据保存失败: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>患者建档</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>患者建档</h1>
|
||||
<form action="patient_90.php" method="post">
|
||||
<label for="patient_name">姓名:</label>
|
||||
<input type="text" id="patient_name" name="patient_name" value=""><br>
|
||||
|
||||
<label for="patient_id">身份证:</label>
|
||||
<input type="text" id="patient_id" name="patient_id" value=""><br>
|
||||
|
||||
<label>性别:</label>
|
||||
<input type="radio" id="male" name="patient_gender" value="1" <?= $patient_gender === '1' ? 'checked' : '' ?>>
|
||||
<label for="male">男</label>
|
||||
<input type="radio" id="female" name="patient_gender" value="2" <?= $patient_gender === '2' ? 'checked' : '' ?>>
|
||||
<label for="female">女</label><br>
|
||||
|
||||
<label for="patient_address">家庭住址:</label>
|
||||
<input type="text" id="patient_address" name="patient_address" value=""><br>
|
||||
|
||||
<input type="submit" id="ok" name="ok" value="ok">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user