I am trying to make it so that my code will check to see the number of tables the database has then increment it then add a table to the database, however, I get the following error? any help would be really appreciated.
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "jobs";
// Create connection
$link = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($link->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result = mysqli_query($link, "show tables");
(int)$num = 0;
while($table = mysqli_fetch_array($result)) {
$num++;
echo($table[0] . "<BR>");
}
$num += 1;
$sql = "CREATE TABLE {$num} (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50)
)";
if(!mysqli_query($link, $sql)){
echo("Error description: " . mysqli_error($link)); }
OUTPUT Error
Error description: 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 '5 ( id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30) N' at line 1