我想将我的网站连接到phpmyadmin数据库,但我无法这样做。
当我回显$insert_product
时,它工作得很好意味着它显示了插入的数据,但是当我删除回声时数据没有上传到phpmyadmin数据库
//connection to db
<?php
$con = mysqli_connect("localhost", "root", "", "ecom");
?>
<!doctype html>
<?php include("includes\db.php"); ?>
<html>
<head>
<meta charset="utf-8">
<title>Insert a Product</title>
</head>
<body bgcolor="#3F3360">
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="1000" border="1" bgcolor="#566043">
<tbody>
<tr align="center">
<td colspan="8">Insert here</td>
</tr>
<tr>
<td><b>Product title</b></td>
<td><input type="text" name="product_title" required/></td>
</tr>
<tr>
<td><b>Product Category</b></td>
<td><select name="product_cat">
<option>Select a Category</option>
<?php $get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while ($row_cats=mysqli_fetch_array($run_cats))
{
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
; ?>
</select>
</td>
</tr>
<tr>
<td><b>Product brand</b></td>
<td><select name="product_brand">
<option>Select Brands</option>
<?php $get_cats = "select * from categories";
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while ($row_brands=mysqli_fetch_array($run_brands))
{
$brand_id = $row_brands['brand_id'];
$brand_title = $row_brands['brand_title'];
echo "<option value='$brand_id'>$brand_title</option>";
}
; ?>
</select>
</td>
</tr>
<tr>
<td>Product Image</td>
<td><input type="file" name="product_image"</td>
</tr>
<tr>
<td>Product Price</td>
<td><input type="text" name="product_price"</td>
</tr>
<tr>
<td>Product Description</td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea></td>
</tr>
<tr>
<td>Product keywords</td>
<td><input type="text" name="product_keywords"</td>
</tr>
<tr>
<td align="center" colspan="8" ><input type="submit" name="insert_post" value="Insert"</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<?php
// Inserting Data to Database
if(isset($_POST['insert_post']))
{
$product_title =$_POST['product_title'];
$product_cat =$_POST['product_cat'];
$product_brand =$_POST['product_brand'];
$product_price =$_POST['product_price'];
$product_desc =$_POST['product_desc'];
$product_keywords =$_POST['product_keywords'];
$product_image =$_FILES['product_image']['name'];
$product_image_tmp =$_FILES['product_image']['tmp_name'];
move_uploaded_file ($product_image_tmp, "product_image/$product_image");
$insert_product = "insert into products (product_cat,product_brand,product_title,product_price,product_desc,product_image,product_keywords)
values ('$product_cat','$product_brand','$product_title','$product_price','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "<script>alert('product instereted')</script>";
echo "<script>window.open('insert_product.php', '_self')</script>";
}
}
mysqli_close($con);
?>