0
我寫過這段代碼,但仍然無法在數據庫中創建表。並且輸出結果爲:表無法創建
「數據庫已創建...對不起表格」。
<?php
include 'connection.php';
//Creating database
$creatingdatabase = "CREATE DATABASE IF NOT EXISTS quest";
$query1 = mysqli_query($con, $creatingdatabase);
if($query1){
echo "database created....";
//creating tables
$creatingtable = "CREATE TABLE quiz (
id INT(6) AUTO_INCREMENT PRIMARY KEY,
questions VARCHAR(255) NOT NULL,
optiona VARCHAR(255) NOT NULL,
optionb VARCHAR(255) NOT NULL,
optionc VARCHAR(255) NOT NULL,
optiond VARCHAR(255) NOT NULL,
answer VARCHAR(50) NOT NULL
)";
$query2 = mysqli_query($con, $creatingtable);
if($query2){echo "table created...";}
else { echo "sorry... table not created"; }
}
else { echo "database can not be created"; }
?>
更改'else {echo「sorry ... table not created」; }'to'else {echo「sorry ... table not created:」。mysqli_error($ con); }'這樣我們可以看到錯誤:) – DiceXQ