Mysqli插入语句 [英] Mysqli insert statement

查看:90
本文介绍了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.";}
}

推荐答案

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

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,?,?,?,?,?,?,?)";

这篇关于Mysqli插入语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆