I'm trying to insert products information into the database, but I must be missing something. It does not insert anything into the database, it's not even showing any errors.
Whats wrong with my code?
<?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);
}
}}
?>
In your query you have add the
product_detail
column two times,there should be one ,as five columns refers to 5 valuesproduct_detail,product_detail,
INSERT INTO product (product_name, product_category, product_price, product_detail, product_company)
VALUES ( '$product_name','$product_category','$product_price','$product_detail','$product_company');
0 comments:
Post a Comment