這是我的代碼。但是每次創建表tblStudents時顯示錯誤。這是爲什麼?儘快需要解決方案。PHP MySQL無法創建表格
<?php
$con=mysqli_connect("localhost","root","noor.xbyte","fathis_quran_class");
if (mysqli_connect_errno()) {
echo '<h1>Error Connecting to the database!</h1>';
} else {
$sql = "CREATE TABLE tblStudents
(
index INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(index),
fullName CHAR(30) NOT NULL,
dateOfBirth DATE NOT NULL,
SID TINYINT NOT NULL,
address CHAR(30) NOT NULL,
level TINYINT NOT NULL,)";
if (mysqli_query($con,$sql)) {
echo 'Table "tblStudents" created successfully!';
} else {
echo 'Error creating table "tblStudents"';
}
}
?>;
'CREATE TABLE tblStudents IF NOT EXISTS'。 http://dev.mysql.com/doc/refman/5.1/en/create-table.html –
在'level TINYINT NOT NULL'之後移除','' – Gautam3164
您可能需要引用索引,因爲它是一個sql保留字 –