Code:
<!DOCTYPE html >
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body>
<form action="insert_product.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="product_title" required="required"></td>
</tr>
<tr>
<td>category</td>
<td><select name="product_category" >
<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_data'];
echo "
<option>$cat_title </option>
";
}
?>
</select></td>
</tr>
<tr>
<td>featured</td>
<td><select name="product_featured" >
<option>0</option>
<option>1</option>
</select></td>
</tr>
<tr>
<td>price</td>
<td><input type="text" name="product_price" required="required"></td>
</tr>
<tr>
<td>image</td>
<td><input type="file" name="product_image" required="required"></td>
</tr>
<tr>
<td>keywords</td>
<td><input type="text" name="product_keywords" required="required"></td>
</tr>
<tr>
<td>description</td>
<td><textarea name="product_description" cols="20" rows="10" ></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Add Product" name="insert_post"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if( isset($_POST['insert_post']))
{
$product_title = $_POST['$product_title'];
$product_category = $_POST['$product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['$product_price'];
$product_keywords = $_POST['$product_keywords'];
$product_description = $_POST['$product_description'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
echo $insert_product = " insert into products (product_cat, product_featured, product_title, product_price, product_desc,product_image,product_keywords) values ('$product_category','$product_featured','$product_title','$product_price','$product_description','$product_image','$product_keywords','$product_keywords')";
}
?>
this is the result I get from this code when I print it with echo
insert into products (product_cat, product_featured, product_title, product_price, product_desc,product_image,product_keywords) values ('','1','','','','champagne culture logo men.png','','')
can someone please tell me what I'm doing wrong? I've checked repeatedly checked to see if i had any spelling errors or anything of that nature but I cant seem to identify exactly what it is that I am doing wrong. Any help you could provide would be greatly appreciated
Remove the $ part from the key:
$product_title = $_POST['$product_title'];
$product_category = $_POST['$product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['$product_price'];
$product_keywords = $_POST['$product_keywords'];
$product_description = $_POST['$product_description'];
Should be
$product_title = $_POST['product_title'];
$product_category = $_POST['product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['product_price'];
$product_keywords = $_POST['product_keywords'];
$product_description = $_POST['product_description'];
You need to change this
$product_title = $_POST['$product_title'];
$product_category = $_POST['$product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['$product_price'];
$product_keywords = $_POST['$product_keywords'];
$product_description = $_POST['$product_description'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
to this
$product_title = $_POST['product_title'];
$product_category = $_POST['product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['product_price'];
$product_keywords = $_POST['product_keywords'];
$product_description = $_POST['product_description'];
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
NOTE
if there was no error, you need to make sure if the input is not empty, you can use empty() property to check if the variable/input is empty.
like
if(empty($_POST['product_title'])) {
echo "product title shouldn't empty";
}
Related
I am getting this error when I run the below code. I dont know why I am getting this error. I echoed the query to make sure that the syntax is correct I checked the query in a syntax checker to make sure that the query contains no syntax errors. and even tested in PHP my admin.
The query that is producing this error is the query that is in the for loop with numberofcolor and numberofsizes
Error description: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
<?php include('includes/db.php'); include('../functions/functions.php');?>
<?php require './p_struct/head.php';?>
<?php require './p_struct/header.php';?>
<?php require './p_struct/sidenav.php';?>
<div class="main" style="font-size: 20px">
<form action="insert_product.php" method="post" enctype="multipart/form-data" class="form-horizontal" id="chells">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="product_title" required="required"></td>
</tr>
<tr>
<td>category</td>
<td><select name="product_category" >
<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_data'];
echo "
<option vallue = '$cat_id' >$cat_title </option>
";
}
?>
</select></td>
</tr>
<tr>
<td>featured</td>
<td><select name="product_featured" >
<option>featured</option>
<option>not featured</option>
</select></td>
</tr>
<tr>
<td>price</td>
<td><input type="text" name="product_price" required="required"></td>
</tr>
<tr>
<td>image</td>
<td><input type="file" name="product_image" required="required"></td>
</tr>
<tr>
<td>big image</td>
<td><input type="file" name="product_big_image" required="required"></td>
</tr>
<tr>
<td>cart image</td>
<td><input type="file" name="product_cart_image" required="required"></td>
</tr>
<tr>
<td>keywords</td>
<td><input type="text" name="product_keywords" required="required"></td>
</tr>
<tr>
<td> Colors</td>
<td>
<div class="checkbox">
<?php
$get_colors = "SELECT * FROM `product_colors`";
$run_get_colors = mysqli_query($con, $get_colors);
while($row_get_color = mysqli_fetch_array($run_get_colors))
{
$colorS = $row_get_color['color'];
echo '<label class="checkbox-inline" ><input type="checkbox" name = "mycolor[]" value="'.$colorS.'" >'.$colorS.'</label>';
}
?>
</div>
</td>
</tr>
<tr>
<td> Sizes</td>
<td>
<div class="checkbox">
<?php
$get_sizes = "SELECT * FROM `product_sizes`";
$run_get_sizes = mysqli_query($con, $get_sizes);
while($row_get_sizes = mysqli_fetch_array($run_get_sizes))
{
$sizesS = $row_get_sizes['size'];
echo '<label class="checkbox-inline" ><input type="checkbox" name = "mysizes[]" value="'.$sizesS.'" >'.$sizesS.'</label>';
}
?>
</div>
</td>
</tr>
<tr>
<td>description</td>
<td><textarea name="product_description" cols="20" rows="5" ></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Add Product" name="insert_post"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
global $con;
if( isset($_POST['insert_post']))
{
$a = rand(100, 999);
$b = rand(100, 999);
$product_id = $a.$b;
$product_title = $_POST['product_title'];
$product_category = $_POST['product_category'];
$product_featured = $_POST['product_featured'];
$product_price = $_POST['product_price'];
$product_keywords = $_POST['product_keywords'];
$product_description = $_POST['product_description'];
$color_array = $_POST['mycolor'];
$sizes_array = $_POST['mysizes'];
$product_image = $_FILES['product_image']['name'];
$product_big_image = $_FILES['product_big_image']['name'];
$product_cart_image = $_FILES['product_cart_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp_name'];
$product_big_image_tmp = $_FILES['product_big_image']['tmp_name'];
$product_cart_image_tmp = $_FILES['product_cart_image']['tmp_name'];
move_uploaded_file($product_image_tmp,"product_images/$product_image");
move_uploaded_file($product__big_image_tmp,"product_big_images/$product_big_image");
move_uploaded_file($product_cart__image_tmp,"product_cart_images/$product_cart_image");
$insert_product = " insert into products (product_id,product_cat, product_featured, product_title, product_price, product_desc,product_image,product_big_image,product_cart_image,product_keywords) values ($product_id,'$product_category','$product_featured','$product_title','$product_price','$product_description','$product_image','$product_big_image','$product_cart_image','$product_keywords')";
$run_insert_query = mysqli_query($con, $insert_product);
$number_of_colors = count($color_array);
for($i=0; $i <$number_of_colors; $i++)
{
$curr_color_value = $color_array[$i];
$add_color_att = "INSERT INTO `attributes`( `id`, `att_type`, `att_value`) VALUES ($product_id, 'color','$curr_color_value');";
$run_add_color_att = mysqli_query($con, $add_color_att);
/* if($run_add_color_att)
{
echo "COLOR ADDED!";
}
else {
echo "COLOR NOT ADDED!";
}*/
}
$number_of_sizes = count($sizes_array);
for($s=0; $s <$number_of_sizes; $s++)
{
$curr_size_value = $number_of_sizes[$s];
$add_size_att = "INSERT INTO `attributes`( `id`, `att_type`, `att_value`) VALUES ($product_id, `size`,`$curr_size_value`)";
$run_add_size_att = mysqli_query($con, $add_size_att);
/* if($run_add_size_att)
{
echo "SIZE ADDED!";
}
else {
echo "SIZE NOT ADDED!";
}*/
}
if($run_insert_query)
{
echo "PRODUCT ADDED!";
}
else {
echo "PRODUCT NOT ADDED!";
}
} ?>
</div>
$add_size_att = "INSERT INTO `attributes`( `id`, `att_type`, `att_value`) VALUES ($product_id, `size`,`$curr_size_value`)";
your using the incorrect quote type here the ` should be ' around the string values:
$add_size_att = "INSERT INTO `attributes`( `id`, `att_type`, `att_value`) VALUES ($product_id, 'size','$curr_size_value')";
also should size be $size?
EDITED I am using HTML forms and PHP to upload data to a MySQL database. When I submit the information an image that i uploaded gets moved to a specific folder(the way i intended it to), but the data does not get uploaded to the data base.
I added most of the code now, the site didn't allow me to add everything, I deleted some lines that in my opinion don't have anything to do with the problem at hand. so maybe you'll see the problem:
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script>
tinymce.init({selector:'textarea'});
</script>
</head>
<body bgcolor="grey">
<form action="insert_product.php" method="post" enctype="multipart/form-
data">
<table align="center" width="795" border="2" bgcolor="lime">
</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>
</td>
</tr>
<tr>
<td align="right"><b>Product Publisher:</b></td>
<td> <select name="product_dev">
<option>Select a Publisher</option>
<?php
$get_devs = "select * from developers";
$run_devs = mysqli_query($con, $get_devs);
while ($row_devs=mysqli_fetch_array($run_devs)){
$dev_id = $row_devs['dev_id'];
$dev_title = $row_devs['dev_title'];
echo "<option value='$dev_id'>$dev_title</option>";
}
?>
</select>
</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 Price:</b></td>
<td><input type="text" name="product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name="product_keywords" size="50"
required/></td>
</tr>
<tr align="center">
<td colspan="7"><input type="submit" name="insert_post"
value="Insert Product Now"/></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
$product_title = $_POST['product_title'];
$product_cat= $_POST['product_cat'];
$product_pub = $_POST['product_pub'];
$product_dev = $_POST['product_dev'];
$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_images/$product_image");
$insert_product = "insert into products
(product_cat,product_pub,product_dev,
product_title,product_price,product_desc,product_image,
product_keywords) values ('$product_cat','$product_pub','$product_dev',
'$product_title','$product_price','$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('index.php?insert_product','_self')
</script>";
}
}
?>
Your query seems fine.
Just verify your MySQLi connection.
It should be like:
$con = mysqli_connect("HOST", "USERNAME", "PASSWORD", "DATABASE_NAME");
This question already has answers here:
"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP
(29 answers)
Closed 5 years ago.
[Errors][1]
I posted the code that I edited, and there are new errors w/c i didn't understand
Notice: Undefined index: product_brand in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 152
Notice: Undefined index: product_price in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 153
Notice: Undefined index: product_images in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 158
Notice: Undefined index: product_images in
C:\xampp\htdocs\JGMarketing\Admin_Area\insert_product.php on line 159
<!DOCTYPE>
<?php
include("includes/db.php");
?>
<html>
<head>
<title>Inserting Product</title>
<script src="https://cloud.tinymce.com/stable/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>
</head>
<body bgcolor="red">
<form action="insert_product.php"method="post"enctype=
"multipart/form/data">
<table align="center" width="700" border="5" bgcolor="white" >
<tr>
<td colspan="8"><h2 style="text-align:center;font-family:Arial;">
Insert New Post Here</h2></td>
</tr>
<tr>
<td align="right"><b>Product Name:</b></td>
<td><input type="text" name= "product_name" size="60" required />
</td>
</tr>
<tr>
<td align="right"><b>Product Category:</b></td>
<td>
<select name="product_cat" required>
<option>Select Category</option>
<?php
global $con;
$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 "<li><option>$cat_title</option></li>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Brand:</b></td>
<td>
<select name="product_brand" required>
<option>Select Brand</option>
<?php
global $con;
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while ($row_brands=mysqli_fetch_array($run_brands)){
$brands_id= $row_brands['brand_id'];
$brands_title= $row_brands['brand_title'];
echo "<li><option>$brands_title</option></li>";
}
?>
</select>
</td>
</tr>
<tr>
<td align="right"><b>Product Image:</b></td>
<td><input type="file" name= "product_image" required /></td>
</tr>
<tr>
<td align="right"><b>Product Price:</b></td>
<td><input type="currency" name= "product_price" required/></td>
</tr>
<tr>
<td align="right"><b>Product Description:</b></td>
<td><textarea name="product_desc" cols="20" rows="10"></textarea>
</td>
</tr>
<tr>
<td align="right"><b>Product Keywords:</b></td>
<td><input type="text" name= "product_keywords" size="50"
required /></td>
</tr>
<tr align="center">
<td colspan="7"><input type="Submit" name= "insert_post" value="Insert
Product Here"/></td>
</tr>
</table>
</body>
</html>
<?php
if(isset($_POST['insert_post'])){
//getting text data
$product_name = $_POST['product_name'];
$product_cat = $_POST['product_cat'];
$product_brands = $_POST['product_brand'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
//getting image data
$product_image = $_FILES['product_images']['name'];
$product_image_tmp = $_FILES['product_images']['tmp_name'];
move_uploaded_file($product_image_tmp,"products_images/$product_image");
$insert_product = "insert into products
(product_cat,product_brands,product_name,product_price,product_desc,
product_img,product_keyword) values ('$product_cat','$product_brands'
,'$product_name','$product_price','$product_desc','$product_image'
,'$product_keywords')";
$run_product = mysqli_query($con,$insert_product);
if($run_product){
echo"<script>alert('Product Has been inserted')</script>";
echo"<script>window.open('insert_product.php','_self')</script>";
}
}
?>
You define your submit button name as "insert_post". But in if condition you take another name (if(isset($_POST['insert_product']))). Change the name.
try use like this...please make sure check your db connection and form action properly.
if(isset($_POST['insert_post'])){
//getting text data from fields
$product_name = $_POST['product_name'];
$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 image from 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");
$insert_product="insert into products (product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price','$product_desc','$product_image','$product_keywords')";
$insert_pro = mysqli_query($con, $insert_product);
if($insert_pro){
echo"alert('Product Has been inserted')";
echo"window.open('insert_product.php','_self')";
}
else{
echo "Something has gone wrong";
}
}
Your Query IS wrong:
$insert_product="insert into products
(product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price',','$product_desc','$product_image','$product_keywords')";
Insert This Query:
$insert_product="insert into products
(product_cat,product_brand,product_name,product_price,product_desc,product_image,product_keywords) values('$product_cat','$product_brand','$product_name','$product_price','$product_desc','$product_image','$product_keywords')";
I am new in php. when form is submitted the data is not storing in database not getting what is wrong in code. Below is my code
<form method="post" action="insert_product.php" enctype="multipart/form-data">
<table width="700" align="center" >
<tr>
<td><h1>Insert New Product</h1></td>
</tr>
<tr>
<td><b>Product Title</b></td>
<td><input type="text" name="product_title"></td>
</tr>
<tr>
<td><b>Product Category</b></td>
<td>
<select name="product_cat">
<option>Select 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 Brand</option>
<?php
$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><b>Product Image1</b></td>
<td><input type="file" name="product_img1"></td>
</tr>
<tr><td><b>Product Image2</b></td>
<td><input type="file" name="product_img2"></td>
</tr>
<tr><td><b>Product Image3</b></td>
<td><input type="file" name="product_img3"></td>
</tr>
<tr>
<td><b>Product Price</b></td>
<td><input type="text" name="product_price"></td>
</tr>
<tr>
<td><b>Product Info</b></td>
<td> <textarea name="product_desc">Easy! You should check out MoxieManager!</textarea></td>
</tr>
<tr>
<td><b>Product Keyword</b></td>
<td><input type="text" name="product_keyword"></td>
</tr>
<tr>
<td><input type="submit" name="insert_product" value="Insert"></td>
</tr>
</table>
</form>
and php code of it
<?php
if (isset($_POST['insert_product'])) {
$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'];
$status = 'on';
$product_keyword = $_POST['product_keyword'];
//image names//
$product_img1 = $_FILES['product_img1']['name'];
$product_img2 = $_FILES['product_img2']['name'];
$product_img3 = $_FILES['product_img3']['name'];
//temp image names
$temp_name1 = $_FILES['product_img1']['tmp_name'];
$temp_name2 = $_FILES['product_img2']['tmp_name'];
$temp_name3 = $_FILES['product_img3']['tmp_name'];
if ($product_title=='' OR $product_cat=='' OR $product_brand=='' OR $product_price=='' OR $product_desc=='' OR $product_keyword=='' OR $product_img1=='' ) {
echo "<script>alert('Please Fill Everything')</script>";
exit();
}
else {
//uploading images to its folder
move_uploaded_file($temp_name1, "product_images/$product_img1");
move_uploaded_file($temp_name2, "product_images/$product_img2");
move_uploaded_file($temp_name3, "product_images/$product_img3");
$insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_price,product_desc,status)
values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2','$product_img3','$product_price','$product_desc','$status')";
$run_product = mysqli_query($con, $insert_product);
if ($run_product) {
echo "<script>alert('Product Inserted')</script>";
}
}
}
?>
Till alert(fill everything) is working means when i click submit without filling form the alert is coming but after that when i filled everything and submit it. But alert is not coming and also data is not saving in database. Please help me. adding my database structure also. Thanks
if(isset($_POST['upload'])){
$name = $_POST['name'];
$album_id = $_POST['album'];
$file = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
$random_name = rand();
if(empty($name) or empty($file)) {
echo "Please Fill all the Fields ! <br /><br />";
} else {
move_uploaded_file$file_tmp, 'uploads/'.$random_name.'.jpg');
mysql_query("INSERT INTO photos VALUE('', '$name', '$album_id', '$random_name.jpg')");
echo "Photo Uploaded !! <br /><br />";
}
}
This is how i managed to do it hope this helps
<?
function openDB()
{
global $conn, $username,$host,$password,$db;
$host = "localhost";
$username ="username";
$password= "password";
$db = "databasename";
$conn = mysql_connect($host, $username,$password) or die(mysql_error());
mysql_select_db($db,$conn) or die(mysql_error());
}
function closeDB()
{
global $conn;
mysql_close($conn);
}
?>
<form action="<? echo $_SERVER[PHP_SELF];?>" method="post" enctype="multipart/form-data">
<table>
<tr>
<td align="left"><b>Product Image:</b></td>
<td><input type="file" accept="image/*" name="product_image" size="60">
</td>
</tr>
<tr>
<td align="left"><b>Product File1:</b></td>
<td><input type="file" accept="*/*" name="product_support_file" size="60">
</td>
</tr>
<tr>
<td align="left"><b>Product File2:</b></td>
<td><input type="file" accept="*/*" name="product_support_file2" size="60">
</td>
</tr>
<tr>
<td align="left"><b>Product Price:</b></td>
<td><input type="text" name="product_price" size="60" required></td>
</tr>
<tr>
<td colspan="7" align="right"><input type="submit" name="insert_product" value="Insert Product Now"></td></tr>
</table>
</form>
<?
openDB();
$product_id = $_POST['product_id'];
$product_title = $_POST['product_title'];
$product_cat = $_POST['product_cat'];
$product_type = $_POST['product_type'];
$product_price = $_POST['product_price'];
$product_desc = $_POST['product_desc'];
$product_keywords = $_POST['product_keywords'];
$product_link = $_POST['product_link'];
//getting the image from the feild
$product_image = $_FILES['product_image']['name'];
$product_image_tmp = $_FILES['product_image']['tmp'];
$product_support_file = $_FILES['product_support_file']['name'];
$product_support_file_tmp = $_FILES['product_support_file']['tmp'];
$product_support_file2 = $_FILES['product_support_file2']['name'];
$product_support_file2_tmp = $_FILES['product_support_file2']['tmp'];
if(isset($_POST['insert_product']))
{
//gets the Text Feild Data
$insert_product = "insert into products(product_id,product_cat, product_type, product_title,
product_price, product_desc, product_image, product_support_file, product_support_file2, product_keywords,product_link)
values('','$product_cat','$product_type','$product_title',
'$product_price','$product_desc','$product_image','$product_support_file','$product_support_file2','$product_keywords','$product_link')";
if(mysql_query($insert_product))
{
//echo "
//Please enter the file path you wish to add your image to:
//<br><input type='text' name='' value=''></input>";
$file_directory ="../yourdirectory";
foreach($_FILES as $file_name => $file_array)
{
if(is_uploaded_file($file_array["tmp_name"]))
{
move_uploaded_file($file_array["tmp_name"],"$file_directory/"
.$file_array["name"]) or die ("Could not copy");
}
}
echo"<script language='Javascript'>window.open('ConformationUpload.php');</script>";
}
else{
echo"Product adding has been unsuccessfull<b>",mysql_error(),"</b>";
}
closeDB();
}
?>