php - Mysqli 插入语句

标签 php insert mysqli

我已经研究了几天了,但我就是找不到它出错的原因。我没有收到 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/

相关文章:

PHP 奇怪的语法 - 它叫什么?

PHP Curl 在下载前检查文件是否存在

sql - 每行插入和每个表插入一个的区别

php - 将数组传递给 Twig 时,带有特殊字符的单词消失了

javascript - 在表中每页显示 50 行,但允许搜索整个表

php - Selenium:如何断言某个元素存在于某个表的某个单元格中?

php - 将文本框 1 和 2 的总和放入文本框 3

c# - MySQL查询在C#中的数据库中插入空值

javascript - 如何通过Javascript函数调用PHP函数来更新mysql表中的数据?

PHP For 循环与 Mysqli 的问题