A
Anonymous
Guest
Code:
</div>
<div>
<div id="form>">
<form action="add_pro.php"method="post" enctype="multipart/form-data">
<table align = "center" width= "80%" border="1" bgcolor="pink" cellpadding="8">
<tr align="center">
<td colspan="7"><h1>Add product</h2></td>
</tr>
<tr>
<td align="right"><b>Product Title:</B></td>
<td><Input type="text" name="product_title" size= "60" required/> </td>
</tr>
<tr>
<td align="right"><b>Product Category:</B></td>
<td>
<select name="product_cat" required/>
<option>select A catogory</option>
<?php
$get_cat ="SELECT * FROM `categories`";
$run_cat = mysqli_query($con, $get_cat);
while ($row_cat=mysqli_fetch_array($run_cat)){
$cat_id = $row_cat['cat_id'];
$cat_title =$row_cat['cat_title'];
echo "<option value='$cat_id'>$cat_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</B></td>
<td> <select name="product_brand" / >
<option>Select Any Brand</option>
<?php
$get_brand ="SELECT * FROM `brands`";
$run_brand = mysqli_query($con, $get_brand);
while ($row_brand=mysqli_fetch_array($run_brand)){
$brand_id = $row_brand['brand_id'];
$brand_title =$row_brand['brand_title'];
echo "<option value='brand_id'>$brand_title</option>";
}
?>
</tr>
<tr>
<td align="right"><b>Product Image:</B></td>
<td> <Input type="file" name="product_image" size= "60"required/> </td>
</tr>
<tr>
<td align="right"><b>Product Price (Inr):</B></td>
<td> <Input type="text" name="product_price" size= "60"/> </td>
</tr>
<tr>
<td align="right"><b>Product Descriptions:</B></td>
<td> <textarea name="product_desc"cols="20" rows="10" /> </textarea> </td>
</tr>
<tr>
<td align="right"><b>Product Keyword:</B></td>
<td> <Input type="text" name="product_keywords"/> </td>
</tr>
<tr><td align="center" colspan="7">
<input type="submit" name ="insert_post" value= "add now"/></td>
<?php
if(isset($_post['insert_post'])){
//getting the text details of the fields
$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'];
//getting the image
$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 $add_pro = "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_keywords','$product_image',)";
$add_pro = mysqli_query($con, $add_product);
if ($add_pro){
echo "<script>alert ('done')</script>";
}
}
?>