【发布时间】:2020-12-12 14:23:50
【问题描述】:
很抱歉这个冗长的问题,但我真的不知道我哪里出错了。我正在尝试使用以下代码在 000webhost 上的数据库中创建三个表(Patients、Beds 和 Appointments):
// PATIENTS
// Create table
$sql_Patients = "CREATE TABLE $tbl_Patients (
patientID BIGINT PRIMARY KEY,
firstName VARCHAR(255),
lastName VARCHAR(255),
age INTEGER(255),
isMale BOOLEAN,
diagnosis VARCHAR(255)
)
";
// Check
echo "About to execute $sql_Patients";
if (mysqli_query($conn, $sql_Patients)) {
echo "Table $tbl_Patients created successfully<br>";
} else {
echo "Error creating table: " . mysqli_error($conn) . "<br>";
}
// Add data
$sql_Patients = "INSERT INTO $tbl_Patients
VALUES (123123123123,'John','Doe',30,1,'Sore throat')
";
// Check
if (mysqli_query($conn, $sql_Patients)) {
echo "New records created successfully<br>";
} else {
echo "Error: " . $sql_Patients . "<br>" . mysqli_error($conn);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// BEDS
// Create table
$sql_Beds = "CREATE TABLE $tbl_Beds (
bedID INTEGER(255) PRIMARY KEY,
size VARCHAR(255),
)
";
// Check
echo "About to execute $sql_Beds";
if (mysqli_query($conn, $sql_Beds)) {
echo "Table $tbl_Beds created successfully<br>";
} else {
echo "Error creating table: " . mysqli_error($conn) . "<br>";
}
// Add data
$sql_Beds = "INSERT INTO $tbl_Beds
VALUES (1,'M')
";
// Check
if (mysqli_query($conn, $sql_Beds)) {
echo "New records created successfully<br>";
} else {
echo "Error: " . $sql_Beds . "<br>" . mysqli_error($conn);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
// APPOINTMENTS
// Create table
$sql_Beds = "CREATE TABLE $tbl_Appointments (
time TIME PRIMARY KEY,
duration INTEGER(255),
)
";
// Check
echo "About to execute $tbl_Appointments";
if (mysqli_query($conn, $tbl_Appointments)) {
echo "Table $tbl_Appointments created successfully<br>";
} else {
echo "Error creating table: " . mysqli_error($conn) . "<br>";
}
// Add data
$sql_Beds = "INSERT INTO $tbl_Appointments
VALUES ('08:00:00','30')
";
// Check
if (mysqli_query($conn, $tbl_Appointments)) {
echo "New records created successfully<br>";
} else {
echo "Error: " . $tbl_Appointments . "<br>" . mysqli_error($conn);
}
但是,当我在我的 Web 服务器数据库上运行代码时,我看到了以下内容:
请指教。谢谢!
【问题讨论】:
-
在大小 VARCHAR(255) 投票后以拼写错误结束的备用逗号