Guest User

Untitled

a guest
Feb 16th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. <?php require_once ("includes/db.php");
  2. ?>
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <title> product</title>
  7. </head>
  8. <body>
  9. <form method="post" action="insert_product.php" enctype="multipart/form-data">
  10. <table width="700" align="center">
  11. <tr>
  12. <td><h2>insert new product</h2></td>
  13. </tr>
  14. <tr>
  15. <td>Product title</td>
  16. <td><input type="text" name="product_title"></td>
  17. </tr>
  18. <tr>
  19. <td>Product category</td>
  20. <td><select name="product_cat">
  21. <option>Select a category</option>
  22. <?php
  23. $get_cats = "select * from category";
  24. $run_cats= mysqli_query($con,$get_cats);
  25. while ($row_cats=mysqli_fetch_array($run_cats))
  26. {
  27. $cat_id = $row_cats['cat_id'];
  28. $cat_title=$row_cats['cat_title'];
  29.  
  30.  
  31.  
  32.  
  33. echo "<option value='$cat_id'>$cat_title</option>";
  34. }
  35.  
  36. ?>
  37. </select>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td>Product brand</td>
  42. <td><select name="product_brand">
  43. <option>Select brand</option>
  44. <?php
  45. $get_brand = "select * from brand";
  46. $run_brand= mysqli_query($con,$get_cats);
  47. while ($row_brand=mysqli_fetch_array($run_brand))
  48. {
  49. $brand_id = $row_brand['brand_id'];
  50. $brand_title=$row_brand['brand_title'];
  51. echo "<option value='$cat_id'>$cat_title</option>";
  52. }
  53.  
  54. ?>
  55. </select>
  56. </td>
  57. </tr>
  58. <tr>
  59. <td>product image1</td>
  60. <td><input type="file" name="product_img1"></td>
  61. </tr>
  62. <tr>
  63. <td>Product image2</td>
  64. <td><input type="file" name="product_img2"></td>
  65. </tr>
  66. <tr>
  67. <td>Product image3</td>
  68. <td><input type="file" name="product_img3"></td>
  69. </tr>
  70. <
  71. <tr>
  72. <td>Product price</td>
  73. <td><input type="number" name="product_price"></td>
  74. </tr>
  75. <tr>
  76. <td>Product desceptration</td>
  77. <td><input type="text" name="product_desc"></td>
  78. </tr>
  79.  
  80. <tr>
  81. <td>Product keyword</td>
  82. <td><input type="number" name="product_keyword"></td>
  83. </tr>
  84. <tr>
  85. <td><input type="submit" value="submit" name="submit"></td>
  86. </tr>
  87.  
  88. </table>
  89.  
  90. </form>
  91. </body>
  92. </html>
  93.  
  94.  
  95. <?php
  96.  
  97. if(isset($_POST['submit']))
  98. {
  99. $product_title=$_POST['product_title'];
  100. $product_cat=$_POST['product_cat'];
  101. $product_brand=$_POST['product_brand'];
  102. $product_price=$_POST['product_price'];
  103. $product_desc=$_POST['product_desc'];
  104. $status='on';
  105. $product_keyword=$_POST['product_keyword'];
  106.  
  107. //image name
  108.  
  109. $product_img1 = $_FILES['product_img1']['name'];
  110. $product_img2 = $_FILES['product_img2']['name'];
  111. $product_img3 = $_FILES['product_img3']['name'];
  112.  
  113. //image temp names
  114.  
  115. $temp_name1 = $_FILES['product_img1']['tmp_name'];
  116. $temp_name2 = $_FILES['product_img2']['tmp_name'];
  117. $temp_name3 = $_FILES['product_img3']['tmp_name'];
  118.  
  119.  
  120. if($product_title=='' OR $product_cat=='' OR $product_brand=='' OR $product_price=='' OR $product_desc=='' OR $product_keyword=='' OR $product_img1=='' OR $product_img2=='' OR $product_img3=='')
  121. {
  122. echo "<script> alert ('please insert the data in the form')</script>";
  123. exit();
  124. }
  125.  
  126. else{
  127. //uploadinimage to the folder
  128. move_uploaded_file($temp_name1,"product_images/$product_img1");
  129. move_uploaded_file($temp_name2, "product_images/$product_img2");
  130. move_uploaded_file($temp_name3,"product_images/$product_img3");
  131.  
  132. }
  133.  
  134. $insert_product = "insert into products (cat_id,brand_id,date,product_title,product_img1,product_img2,product_img3,product_brand,product_price,product_desc,status) values ('$product_cat','$product_brand',NOW(),'$product_title','$product_img1','$product_img2',$product_img3,'product_brand','product_price','product_desc','product_keyword')";
  135. $row = mysqli_connect("$con,$insert_product");
  136. if($row)
  137.  
  138. {
  139. echo "<script> alert('insert sucessfully')</script>";
  140. }
  141. else
  142. {
  143. echo "<script> alert(' unsucessfull to insert')</script>";
  144. }
  145. }
  146. ?>
Add Comment
Please, Sign In to add comment