我已经研究了几天了,但我就是找不到它出错的原因。我没有收到 php 警告,只是错误处理程序“出现问题”而不是插入。我知道这里优秀的小伙子们可能会在几秒钟内发现它,尤其是考虑到它只是一个简单的插入语句,但我很烦。提前致谢。
include('core.inc.php');
$sql = 'INSERT INTO $resultsTable (
id,
firstName,
lastName,
email,
birthday,
anniversary,
location,
campaign
)
VALUES (NULL,?,?,?,?,?,?,?)';
$stmt = $mysql->stmt_init();
if ($stmt->prepare($sql)) {
// bind parameters and execute statement
$stmt->bind_param(
'sssssss',
$_POST['fname'],
$_POST['lname'],
$_POST['email'],
$_POST['birthday'],
$_POST['anniversary'],
$_POST['location'],
$campaign
);
$OK = $stmt->execute();}
// return if successful or display error
if ($OK) {$response = "Success";}
else {$response ="Something went wrong.";}
}
最佳答案
ok i echoed stmt error and it told me that $resultsTable didnt exist. In core.inc, I have a definition for that variable
使用连接或双引号。
$sql = 'INSERT INTO ' . $resultsTable . ' (
id,
firstName,
lastName,
email,
birthday,
anniversary,
location,
campaign
)
VALUES (NULL,?,?,?,?,?,?,?)';
$sql = "INSERT INTO $resultsTable (
id,
firstName,
lastName,
email,
birthday,
anniversary,
location,
campaign
)
VALUES (NULL,?,?,?,?,?,?,?)";
关于php - Mysqli 插入语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10260152/