Insert Image With Unique Number Using PHP Mysqli



<?php
                                    include "config.php";
                                    if(isset($_POST['btn_rgister']))
                                    {
                                    extract($_POST);

                                    $name1=$_FILES['product_photo']['name'];
                                    $size=$_FILES['product_photo']['size'];
                                    $type=$_FILES['product_photo']['type'];

                                    $temp=$_FILES['product_photo']['tmp_name'];
                                    $RandomImageName = uniqid();
                                    move_uploaded_file($temp,"productimages/".$RandomImageName);
                                   
                                    $query="insert into products(product_name,product_category,product_photo,product_description,product_price,product_availabel_quantity,product_note) values('$product_name','$product_category','$RandomImageName','$product_description','$product_price','$product_availabel_quantity','$product_note')";
                                    $res=mysqli_query($con,$query) or die(mysqli_error($con));
                                    if($res)
                                      {
                                        echo "<script>";
                                        echo "alert('New Product Added Successfully');";
                                        echo "window.location.href='view_product.php';";
                                        echo "</script>";
                                      }
                                      else
                                      {
                                        echo "<script>";
                                        echo "alert('Error! Product Not Added');";
                                        echo "window.location.href='add_product.php';";
                                        echo "</script>";
                                      }
                                    }
                                    ?>
Previous
Next Post »