我正在使用以下php语法:
$sqlgo = "INSERT INTO invoice_qtydisc (`invoice_id`,`name`,`description`,`price`,`qty`,`discount`,`created`,`created_by`) VALUES ('$invoice_id','$product','$description','$price','$qty','$discount',NOW(),'$update_id')";
$dbconnect->query($sqlgo);
当PHP执行上面的代码时,什么也没有插入数据库,但是当我回显$ sqlgo并在phpMyAdmin中执行它时,一切似乎都很好。这是sql的echo示例:
INSERT INTO invoice_qtydisc (`invoice_id`,`name`,`description`,`price`,`qty`,`discount`,`created`,`created_by`) VALUES ('118','Sport Socks','','20.00','1','0',NOW(),'1')
我错过了什么吗?保持.. lemme粘贴整个for循环,以防万一:
$item_maintain = array();
$test = 0;
$sqlgo = "";
for($i=0;$i<count($invoice_product);$i++) {
if(!empty($invoice_product[$i])) {
$product = addslashes($invoice_product[$i]);
$description = addslashes($invoice_product_desc[$i]);
$qty = trim($invoice_product_qty[$i]);
$price = trim($invoice_product_price[$i]);
if (!$invoice_product_discount[$i]) {
$discount = 0;
} else {
$discount = trim($invoice_product_discount[$i]);
}
if (!empty($item_current[$i])) {
$dbconnect->query("UPDATE invoice_qtydisc SET name='$product', description='$description', price='$price', qty='$qty', discount='$discount', updated=NOW(), updated_by='$update_id' WHERE id='$item_current[$i]'");
array_push($item_maintain, $item_current[$i]);
} else {
$sqlgo = "INSERT INTO invoice_qtydisc (`invoice_id`,`name`,`description`,`price`,`qty`,`discount`,`created`,`created_by`) VALUES ('$invoice_id','$product','$description','$price','$qty','$discount',NOW(),'$update_id')";
$dbconnect->query($sqlgo);
$dbconnect->query("INSERT INTO pin_board (title,message) VALUES ('title here','message here')");
$test++;
}
}
}
“ pin_board”表中的第二条插入行运行正常。