字段未在phpmailer脚本中输入mysql数据库

时间:2016-11-17 10:34:44

标签: php mysql

我正在编辑iDEAL付款的预制脚本here。我要做的是在表单和数据库中添加几个字段。额外的字段在电子邮件模板中显示正常,但它们不会输入到数据库中。该脚本适用于PHPmailer。

我认为这就是问题所在:

$stmt = $db->prepare("INSERT INTO tbl_ideal_payments SET 
                ID = ?, datumtijd = NOW(), 
                naamfrom = ?, emailfrom = ?, 
                naamto = ?, emailto = ?, 
                bedrag = ?, descr = ?, 
                mailsubject = ?, mailtekst = ?, 
                ipadres = ?, 
                heenreis = ?, 
                terugreis = ?, 
                postcode = ?, 
                factuurnummer = ?, 
                status = 'open'");
//var_dump($stmt);
$stmt->bind_param('sssssdssss', $session, $naamfrom, $emailfrom, $contact, $emailto, $bedrag, $paydecr, $subject, $mailmsg, $heenreis, $terugreis, $postcode, $factuurnummer, $_SERVER['REMOTE_ADDR']);

我试图添加的字段是heenreis,terugreis,postcode和factuurnummer。

可以找到配置,表单和上面脚本的完整代码here(在这篇文章中似乎有点太多了。)

我做错了什么?

1 个答案:

答案 0 :(得分:1)

计算数据类型参数'sssssdssss',然后计算参数占位符?,然后计算SET子句中的列,它们应该都是相同的数字。

此情况也会产生错误,但您没有测试错误

在开发过程中,特别是如果您在应该关闭错误报告的LIVE服务器上进行开发,请在脚本顶部添加这些行,以打开错误报告。

<?php 
ini_set('display_errors', 1); 
ini_set('log_errors',1); 
error_reporting(E_ALL); 
// if you are using the MYSQLI_ database extension add this also
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);


$stmt = $db->prepare("INSERT INTO tbl_ideal_payments SET 
                ID = ?, datumtijd = NOW(), 
                naamfrom = ?, emailfrom = ?, 
                naamto = ?, emailto = ?, 
                bedrag = ?, descr = ?, 
                mailsubject = ?, mailtekst = ?, 
                ipadres = ?, 
                heenreis = ?, 
                terugreis = ?, 
                postcode = ?, 
                factuurnummer = ?, 
                status = 'open'");

// also add error test
if ( !$stmt ) {
    echo $db->error;
    exit;
}

// now add the 4 missing data type parameters
// I have assumed they are all string !!!
// You should check with your schema what datatype they actually are

$stmt->bind_param('sssssdssssssss', $session, 
                                    $naamfrom, 
                                    $emailfrom, 
                                    $contact, 
                                    $emailto, 
                                    $bedrag, 
                                    $paydecr, 
                                    $subject, 
                                    $mailmsg, 
                                    $heenreis, 
                                    $terugreis, 
                                    $postcode, 
                                    $factuurnummer, 
                                    $_SERVER['REMOTE_ADDR']
                );