我正在编辑一个预先制作的iDEAL付款脚本,可以在这里使用。我要做的是添加一些字段的形式和数据库。额外的字段在电子邮件模板中显示得很好,但没有输入到数据库中。该脚本与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']);
我要添加的字段是地址、地址、邮政编码和工厂编号。
配置、表单和上述脚本的完整代码可以在这里找到(似乎在这篇文章中粘贴得太多了)。
我做错了什么?
先计算数据类型参数'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']
);