MySQLI Prepared语句不会插入DB

时间:2013-12-21 14:19:44

标签: php mysqli

在我得到建议将我的正常MySQLI查询更改为准备好的语句后,我试图将其全部更改为准备好的语句。唯一的问题是,我的查询不会将信息插入数据库。

我尝试使用var_dump来了解是否有问题,但是var_dump给了我这个回复:

  

警告:var_dump()[function.var-dump]:属性访问不是   允许在/home/*/domains/**.nl/public_html/contact.php   第123行对象(mysqli_stmt)#3(9){[“affected_rows”] =>空值   [ “INSERT_ID”] => NULL [“num_rows”] => NULL [“param_count”] =>空值   [ “场计数”] => NULL [“errno”] => NULL [“error”] =>空值   [ “SQLSTATE”] => NULL [“id”] => NULL}

我的代码:

            $stringMelding  = '<div class="attention closable"><strong>Helaas!</strong> Er is helaas een onbekende fout opgetreden met onze database, probeert u het later nog eens.</div>';
    $emailSent      = true;

//Controle spam.    
if($sDatum == $arrayInfoContact['datum'] && $sIPadres == $arrayInfoContact['ipadres'])
{
  $stringMelding = '<div class="warning closable"><strong>Helaas!</strong> U heeft in de afgelopen 24 uur al een bericht verzonden naar onze helpdesk!</div>';
}
else
{
  $stringMelding  = '<div class="success closable"><strong>Bedankt!</strong> Uw e-mail is verstuurd naar onze helpdesk, wij zullen zo snel mogelijk contact met u opnemen.</div>';

  //Prepared statement.
  $stmt  = $mysqli->prepare("INSERT INTO contact(naam, mailadres, bericht, ipadres, datum) VALUES (?, ?, ?, ?, ?)");
  $stmt->bind_param('sssss', $sName, $sEmail, $sMessage, $sIPadres, $sDatum);

    $sName     = $mysqli->real_escape_string(trim($_POST['author']));
    $sEmail    = $mysqli->real_escape_string(trim($_POST['email']));
    $sMessage  = trim(nl2br($_POST['comment']));
    $sIPadres  = $_SERVER['REMOTE_ADDR'];
    $sDatum    = date('d-m-Y');

  $stmt->execute();
  $stmt->close();
  //End of prepared statement.

  $mail           = mail($afMail, "Contact || RASolutions", $sBericht, $headers);

当我使用MySQLI-&gt;查询时,我的查询和整个系统都有效,所以我想这个查询正常工作,谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

在连接

之前添加这些行
ini_set('display_errors',1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

再次运行你的代码并查看它抛出的错误