I can't find a mistake in my code, and I always get the following error:
exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens' "
when trying to submit some inputs from a form.
if (isset($_GET['createNewBox'])) {
if (!empty($_POST['tableName']) and !empty($_POST['commentFullAddress'])) {
try{
$sql = 'CREATE TABLE :tableName (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
customerid INT,
item TEXT,
pin INT(11) NOT NULL,
position VARCHAR(5),
storedate DATE NOT NULL,
storetime TIME NOT NULL
) DEFAULT CHARACTER SET utf8 ENGINE=INNODB COMMENT=":commentFullAddress"';
$statement = $pdo -> prepare($sql);
$statement -> bindValue(':tableName', $_POST['tableName']);
$statement -> bindValue(':commentFullAddress', $_POST['commentFullAddress']);
if ($statement -> execute()) {
session_start();
$_SESSION['messageSucceed'] = "A new database has been created for the box.";
header('Location: /?managebox');
exit();
}
} catch (PDOException $e) {
$error_output = "Error on creating new box database: " . $e;
include '../error.html.php';
exit();
}
} else {
session_start();
$_SESSION['message'] = "Please do not submit empty data.";
header("Location: /?managebox");
}
}