I am trying to create a table with mysqli and give it prefixed name using a pre-defined constant, but i can't get it to work would you please check the code and tell me what is wrong.
<?php
$servername = "localhost";
$dbname = "users";
$username = "root";
$password = "";
define("TABLE_PREIX","xjk");
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// sql to create table
$sql = "CREATE TABLE ".TABLE_PREIX."-users (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if ($conn->query($sql) === TRUE) {
echo "Table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
?>
Edit:
Here is the error:
Error creating table: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-users ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCH' at line 1