繁体   English   中英

无法插入mysql表-mysqli错误不起作用

[英]Cannot insert into mysql table - mysqli error not working

我正在尝试将一些数据插入到mysql表中,但是该过程没有通过,并且没有得到任何打印错误的信息。 我认为我没有正确输出错误。 看着php.net,似乎我在正确地处理错误,但也许我遗漏了一些东西。

这是代码

$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
$sqlInsert = $db->query("INSERT INTO transactions(`user_id`, `courses`, `invoice`, `start_date`, `end_date`, `mc_gross`, `email`) VALUES ('".$user_id."','".$trim."','".$invoice."','".$start_date."','".$end_date."', '".$email."')");


if($sqlInsert)
    {
    echo "Inserted successfully";
    }
    else
      {
       printf("Error: ", $db->error);

       }

变量的值如下

$custom = $_SESSION['custom'];
$user_id = $_POST['userID'];
$pwd = $_POST['password'];
$email = $_POST['email'];
$start_date = date('Y-m-d');
$end_date = date (('Y-m-d'), strtotime('+120 days'));
$invoice = date('Ymd'). mt_rand(1252,10000);
$invoice_check = $db->query("SELECT `invoice` FROM `transactions` WHERE `invoice` = $invoice");
while ($rows = $invoice_check->fetch_assoc())
{
    $invoice = date('Ymd'). mt_rand(1252,10000);   
}
$mc_gross = $_SESSION['subtotal'];
$trim = rtrim($custom, ",");

$ trim的var_dump是string(17) "bio_01,calculus_01" ,其他变量只是按您期望的那样正常回显。

有任何想法吗?

编辑用$ db而不是$ sqlInsert更新了代码。 仍然没有错误输出。

更改:

printf("Error: ", $sqlInsert->error);

至:

printf("Error: %s", $db->error);

您无法读取falseerror属性,因为它不是对象。 而且您在printf格式字符串中缺少%s来替代参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM