我正在尝试将产品信息插入数据库,但我一定遗漏了一些东西。它不会向数据库中插入任何内容,甚至没有显示任何错误。
我的代码有什么问题?
<?php
if(!empty($product_name)){
if(!empty($product_category)){
////////////////////////////////////////////////
///// connect to database
////////////////////////////////////////////////
$dbc = new mysqli("localhost", "root", "password", "table");
// Check connection
if (mysqli_connect_errno($dbc)) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_POST['product_name'])) {
$pid = ($_POST['thisID']);
$product_name = ($_POST['product_name']);
$product_category = ($_POST['product_category']);
$product_detail = ($_POST['product_detail']);
$product_price = ($_POST['product_price']);
$product_company = ($_POST['product_company']);
$query = "INSERT INTO product (product_name, product_category, product_price, product_detail,product_detail, product_company)
VALUES ( '$product_name','$product_category','$product_price','$product_detail','$product_company')";
$result= $this->mysqli->query($query) or die(mysqli_connect_errno()."Data cannot inserted");
if($result){
header('location:cp_product.php');
}
mysqli_close($dbc);
}
}}
?>