入力フィールドが空かどうかをチェックする単純なコードを書きました。空でない場合、そのフィールドに入力された内容は、新しく作成されたデータベース TABLE の名前になります。しかし、その名前のテーブルが既に存在するかどうかをコードで確認する必要がある部分に問題があります。これは私がこれまでに持っているものです:
include 'conn.php';
$entry_name = $_POST['entry_name'];
// Check if the field is empty
if(empty($_POST['entry_name'])) {
echo "Please, fill the name field!";
}
// If the field is full
else {
// Check for the duplicated table names
$result = mysql_query(**???**);
if($result == $entry_name) {
die("Entry with that name already exists, choose a different name!");
}
// If there are no tables with entered name, create the new table
else {
$entry_name = mysql_real_escape_string($_POST['entry_name']);
mysql_query("CREATE TABLE `" . $entry_name . "` ( first VARCHAR(30), second VARCHAR(30))");
echo "$entry_name created successfully!";
}
}
疑問符が付いている部分は、正確に何をすべきかわからない場所です。