Mysqli插入声明

kil*_*oad 6 php mysqli insert

我已经过了几天了,我只是找不到错误的原因.我没有得到一个PHP警告,只是错误处理程序"somethign出错"而不是插入.我知道这里优秀的年轻小伙子可能会在几秒钟内发现它,特别是考虑到它只是一个简单的插入声明,但我有点不知所措.提前致谢.

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.";}
}
Run Code Online (Sandbox Code Playgroud)

Sta*_*lin 3

好吧,我回显了 stmt 错误,它告诉我 $resultsTable 不存在。在 core.inc 中,我有该变量的定义

使用串联或双引号。

$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,?,?,?,?,?,?,?)";
Run Code Online (Sandbox Code Playgroud)