我已完成此功能以插入新产品:
function insertProduct($product) {
$db = connect_db();
$columnsNames = $paramsNames = "";
foreach ($product as $key => $value) {
$columnsNames .= "$key,";
$paramsNames .= ":$key,";
}
$columnsNames = substr($columnsNames,0,strlen($columnsNames)-1);
$paramsNames = substr($paramsNames,0,strlen($paramsNames)-1);
$insertProductQuery = "INSERT INTO products ($columnsNames) VALUES ($paramsNames)";
$insertProduct = $db->prepare($insertProductQuery);
foreach ($product as $key => $value) {
$insertProduct->bindParam(":$key", $value);
}
$insertProduct->execute();
$idProduct = $db->lastInsertId();
return $idProduct;
}
但是,在“内部代码”中插入“ean代码”的值。现在我给你更多细节。
进入“bindParam foreach”我插入:
echo "$key | $value <br>";
它回声:
在数据库中,它也将“Codice EAN6”插入“internalCode”......你能找到我看不到的东西吗?
谢谢!