本文介绍了Mysqli插入语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经花了几天时间了,我只是找不到错误的原因.我没有得到php警告,只是错误处理程序"somethign出错了",而不是插入.我知道这里的好小伙子可能会在几秒钟内发现它,尤其是考虑到它只是一个简单的插入语句,但我对此感到困惑.预先感谢.
Ive been going over this for a couple days and i just cant find the reason it is erroring out. Im not getting a php warning, just the error handler "somethign went wrong" instead of inserting. I know the fine young lads here will probably spot it in a few seconds, esp considering its just a simple insert statement, but im buggered. Thanks in advance.
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.";}
}
推荐答案
使用串联或双引号.
$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,?,?,?,?,?,?,?)";
这篇关于Mysqli插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!