因此,我正在创建一个电子商务系统,并成功地建立了主要的比特。到目前为止,我的数据库运行着两个表,“categories”和“products”。
类别已成功连接到my index.php文件,但产品未连接。基本上,如果我将数据从html文件插入到类别中,它将显示在phpmyadmin上,但对于产品来说,情况就不一样了。
我将张贴下面的相关文件的代码。我真的很感谢一些帮助在这个问题上,我已经被困在这几天了!谢谢您
如果你想让我给你发邮件整个文件夹,请让我知道
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
</head>
<body bgcolor="limegreen">
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table align="center" width="750px" border="2" bgcolor="white">
<tr align="center">
<td colspan="7">
<h2>Insert New Product Here</h2>
</td>
</tr>
<tr>
<td align="right"><b>Product Title:</b></td>
<td><input type="text" name="product_title" size="50" /></td>
</tr>
<tr>
<td align="right"><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>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="text" name="product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Quantity:</b></td>
<td><input type="text" name="product_quantity" /></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="40" rows="10" /></textarea>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name="product_image" /></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name="product_keywords" size="50" /></td>
</tr>
<tr align="center">
<td colspan="7"><input type="submit" name="insert_post" value="Insert Product Now" /></td>
</tr>
</table>
</form>
</body>
</html>enter code here
<?php
if(isset($_POST['insert_post'])){
//getting text data from fields
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_price = $_POST['product_price'];
$product_quantity = $_POST['product_quantity'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting the image from the fields
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
echo $insert_product = "insert into product (product_title,product_cat,product_price,product_quantity,product_desc,product_image,product_keywords) values ('$product_title','$product_cat','$product_price','$product_quantity','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo "<script>alert('Product has been inserted!')</script>";
echo "<script>window.open('insert_product.php','_self')</script>";
}
}
?>
暂无答案!
目前还没有任何答案,快来回答吧!