Add product with images upload in php.

<?php
include("adminpanel.php");
include("Database.php");
$sql="select * from department";
$sql1="select * from brand";
$sql2="select * from bridge_type";
$sql3="select * from face_shape";
$sql4="select * from facial_features";
$sql5="select * from frame_type";
$sql6="select * from framematerial";
$sql7="select * from hinge_type";
$sql8="select * from lens_type";
$sql9="select * from frame_color";
?>
<html>
<head>
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
<script src="js/jquery-1.8.2.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
function random()
{
var generator = Math.floor(Math.random()*1000000);
     var ss="TULIP"+""+generator;
     document.getElementById("productid").value=ss;
}
$(document).ready(function() {
    $("#department").change(function() {
        $.ajax({
             type: "GET",
             url: "loadsubcat.php",
             data: {
input: $('#department').val()
}
             }).done(function( data ) {
             $("#subdepart").html(data);
             
             });
    });
});
</script>
<style type="text/css">
body
{
text-align:center;

}
table tr td
{
font-family: Arial, Helvetica, sans-serif;
font-size:15px;
color: #000;
margin:8px;
padding:1px;
}
input[type="text"]
{
border: 2px solid #DDDDDD;
    border-radius: 3px;
    display: block;
    font: 400 1em/1 "Open Sans",sans-serif;
    
    margin: 0 0 0.5em;
    padding: -1.2em 1.25em;
    transition: border-color 300ms ease 0s, color 300ms ease 0s;
   width: 69%;
    height: 26px;
    font-size: 15px;
}
input[type="file"]
{

    border-radius: 3px;
    display: block;
    font: 400 1em/1 "Open Sans",sans-serif;
    
    margin: 0 0 0.5em;
    padding: -1.2em 1.25em;
    transition: border-color 300ms ease 0s, color 300ms ease 0s;
    
}
input[type="submit"]
{
font-family:Arial, Helvetica, sans-serif;
font-size:15px;
width:115px;
margin:8px;
padding:1px;
}
input[type="reset"]
{
font-family:Arial, Helvetica, sans-serif;
font-size:15px;
width:90px;
margin:8px;
padding:1px;
}
select
{
 border: 2px solid #DDDDDD;
    border-radius: 3px;
    display: block;
    font: 400 1em/1 "Open Sans",sans-serif;
    
    margin: 0 0 0.5em;
    padding: -1.2em 1.25em;
    transition: border-color 300ms ease 0s, color 300ms ease 0s;
    width: 69%;

}
</style>
</head>
<body onLoad="random()">
<div style="margin:0 auto;width:500px;">
<div style="margin:0 auto;">
<form align="center" enctype="multipart/form-data" action="insertproduct.php" method="post">

<table >
<tr>
<td><h3>Add Product</h3></td>
<td>
<tr>
<td>Select Categories</td>
<td>
<select name="department" id="department">
<option>----------------------Select----------------------</option>
<?php
$ret=mysql_query($sql);
while($row=mysql_fetch_array($ret))
{
?>
<option value="<?php echo $row[0];?>"><?php echo $row[1];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Select Sub-Categories</td>
<td>
<select name="subdepartment" id="subdepart">
<option>----------------------Select----------------------</option>
</select>
</td>
</tr>
<tr>
<td>Product Name</td>
<td><input type="text"  name="productname" placeholder="Product Name" /></td>
</tr>
<tr>
<td>Product ID</td>
<td><input type="text"  name="productid" id="productid" /></td>
</tr>
<tr>
<td>Select Brand</td>
<td>
<select name="brand">
<option>----------------------Select----------------------</option>
<?php
$ret1=mysql_query($sql1);
while($row1=mysql_fetch_array($ret1))
{
?>
<option value="<?php echo $row1[0];?>"><?php echo $row1[1];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Vendor Name</td>
<td><input type="text"  name="vendor" placeholder="Vendor Name" /></td>
</tr>
<tr>
<td>Product MRP(In Rupees)</td>
<td><input type="text"  name="mrp" placeholder="Product MRP"  /></td>
</tr>
<tr>
<td>Our Product Price(In Rupees)</td>
<td><input type="text"  name="ourmrp" placeholder="Product MRP" /></td>
</tr>
<tr>
<td>Product Quantity</td>
<td><input type="text"  name="quantity" placeholder="Product Quantity" /></td>
</tr>
<tr>
<td>Delivery Time</td>
<td><input type="text"  name="time" placeholder="Delivery Time" /></td>
</tr>
<tr>
<td>Frame Type</td>
<td>
<select name="type">
<option>----------------------Select----------------------</option>
<?php
$ret5=mysql_query($sql5);
while($row5=mysql_fetch_array($ret5))
{
?>
<option value="<?php echo $row5[0];?>"><?php echo $row5[1];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Temple Size</td>
<td><input type="text"  name="temple" placeholder="Temple Size" /></td>
</tr>
<tr>
<td>Frame Color</td>
<td><input type="text"  name="color" placeholder="(put comma between more than two colors)" /> </td>
</tr>
<tr>
<td>Style</td>
<td><input type="text"  name="Style" placeholder="Style" /></td>
</tr>

<tr>
<td>Lens Type</td>
<td><select name="lens">
<option>----------------------Select----------------------</option>
<?php
$ret8=mysql_query($sql8);
while($row8=mysql_fetch_array($ret8))
{
?>
<option value="<?php echo $row8[0];?>"><?php echo $row8[1];?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td>Size</td>
<td><input type="text"  name="size" placeholder="(put comma between more than two size)" /> </td>
</tr>
<tr>
<td>Gender</td>
<td>
<select name="gender">
<option>----------------------Select----------------------</option>
<option>Male</option>
<option>Female</option>
</select></td>
</tr>
<tr>
<td>Applicable ShippingCharges</td>
<td>
<select name="ship">
<option>----------------------Select----------------------</option>
<option>Yes</option>
<option>No</option> </td>

</tr>
<tr>
<td>Charges(In Rupees)</td>
<td><input type="text"  name="Charges" placeholder="Charges" /> </td>
</tr>

<tr>
<td><h3>Product Images</h3></td>
</tr>
<tr>

</tr>
<tr>
<td><h4>Main Image</h4></td>
<td><input type="file" name="file0"></td>
</tr>
<tr>
<td>Image2</td>
<td><input type="file" name="file1"></td>
</tr><tr>
<td>Image3</td>
<td><input type="file" name="file2"></td>
</tr>
<tr>
<td>Image4</td>
<td><input type="file" name="file4"></td>
</tr><tr>
<td>Image5</td>
<td><input type="file" name="file5"></td>
</tr>
<tr>
<td>Image6</td>
<td><input type="file" name="file6"></td>
</tr>
<tr>
<td><h4>Product Description</h4></td>
</tr>
<tr>
<td colspan="2"><textarea rows="10" cols="67" name="des" id="des"></textarea></td>
</tr>
<tr>
<td colspan="2" style="text-align:right"><input type="submit" value="ADD PRODUCT">
<input type="RESET" value="RESET"></td>
</tr>
</table>

</form>


<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
CKEDITOR_BASEPATH = 'ckeditor';

var editor = CKEDITOR.replace('des', {
    filebrowserBrowseUrl: "kcfinder/browse.php?type=files",
width: "700px",
        height: "400px"
});
</script>
</div>
</div>
</body>
</html>
<?php
mysql_close($con);
?>






insertproduct.php


<?php
include("Database.php");
$filename0=$_FILES["file0"]["name"];
$parts0=explode('.',$_FILES['file0']['name']);
$newName0=rand(1,1000000).'.'.$parts0[(count($parts0)-1)];
$path0="upload/product/$newName0";
$fill0=$_FILES["file0"]["tmp_name"];

$filename1=$_FILES["file1"]["name"];
$parts1=explode('.',$_FILES['file1']['name']);
$newName1=rand(1,1000000).'.'.$parts1[(count($parts1)-1)];
$path1="upload/product/$newName1";
$fill1=$_FILES["file1"]["tmp_name"];

$filename2=$_FILES["file2"]["name"];
$parts2=explode('.',$_FILES['file2']['name']);
$newName2=rand(1,1000000).'.'.$parts2[(count($parts2)-1)];
$path2="upload/product/$newName2";
$fill2=$_FILES["file2"]["tmp_name"];

$filename3=$_FILES["file6"]["name"];
$parts3=explode('.',$_FILES['file6']['name']);
$newName3=rand(1,1000000).'.'.$parts3[(count($parts3)-1)];
$path3="upload/product/$newName3";
$fill3=$_FILES["file6"]["tmp_name"];

$filename4=$_FILES["file4"]["name"];
$parts4=explode('.',$_FILES['file4']['name']);
$newName4=rand(1,1000000).'.'.$parts4[(count($parts4)-1)];
$path4="upload/product/$newName4";
$fill4=$_FILES["file4"]["tmp_name"];

$filename5=$_FILES["file5"]["name"];
$parts5=explode('.',$_FILES['file5']['name']);
$newName5=rand(1,1000000).'.'.$parts5[(count($parts5)-1)];
$path5="upload/product/$newName5";
$fill5=$_FILES["file5"]["tmp_name"];
if(move_uploaded_file("$fill0","$path0")&&move_uploaded_file("$fill1","$path1")&&move_uploaded_file("$fill2","$path2")&&move_uploaded_file("$fill3","$path3")&&move_uploaded_file("$fill4","$path4")&&move_uploaded_file("$fill5","$path5"))
{
$a=$_POST["productid"];
$b=$_POST["productname"];
$c=$_POST["brand"];
$d=$_POST["department"];
$e=$_POST["subdepartment"];
$f=$_POST["mrp"];
$g=$_POST["vendor"];
$h=$_POST["ourmrp"];
$i=$_POST["quantity"];
$j=$_POST["time"];
$k=$_POST["type"];
$l=$_POST["temple"];
$m=$_POST["color"];
$n=$_POST["Style"];
$o=$_POST["lens"];
$p=$_POST["size"];
$q=$_POST["gender"];
$r=$_POST["ship"];
$s=$_POST["Charges"];
$t=$_POST["des"];
$u=$_POST["subdepartment"];
$sql="insert into product(Product_ID,Product_Name,Brand_ID,Department_ID,MRP,Vendor_Name,Landing_Cost,Quantity,Delivery_Time,Type_ID,Temple,Frame_Color,Style,Lens_ID,Size,Gender,Shippingcharge,charge,Image1,Image2,Image4,Image5,Image3,Image6,Description,Sub_DepartmentID,status) values('$a','$b','$c','$d','$f','$g','$h','$i','$j','$k','$l','$m','$n','$o','$p','$q','$r','$s','$newName0','$newName1','$newName2','$newName3','$newName4','$newName5','$t','$u','UnActive')";
$ret=mysql_query($sql);
if($ret)
{
$message = "added";

echo "<script type='text/javascript'>alert('$message');</script>";
header("location:addproduct.php");

}
else
{
$message = "Some Error";

echo "<script type='text/javascript'>alert('$message');</script>";
//echo mysql_error();
header("location:addproduct.php");

}
}
else
{
$message = $_FILES["file0"]["error"];

echo "<script type='text/javascript'>alert('$message');</script>";
echo "file Upload error no-"."$message";
header("location:addproduct.php");

}
?>

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.