Guest User

Untitled

a guest
Sep 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <?php
  2. echo '<div id="content" class="container" style="new.css">';
  3. echo '<form action="Addproducts.php" method="post" enctype="multipart/form-data" class="form-horizontal well col-xs-8 col-xs-offset-2">';
  4. echo '<input type="text" id="text" name="image_text"></input>';
  5. echo ' <div class="form-group">';
  6. echo '<input type="file" name="image"/>';
  7. echo '</div>';
  8. echo ' <div class="form-group">';
  9. echo ' <center> <input type="submit" name="submit" value="Enter"/> </center>';
  10. echo ' </div>';
  11. echo '</form>';
  12. //end of html part
  13.  
  14. if(isset($_POST["submit"]))
  15. {
  16. $dbHost = 'localhost';
  17. $dbUsername = 'root';
  18. $dbPassword = '';
  19. $dbName = 'mydb';
  20. $image = $_FILES['image']['name'];
  21.  
  22. $mysqli = new mysqli("localhost", "root", "", "mydb");
  23.  
  24. $image_text = mysqli_real_escape_string($mysqli , $_POST['image_text']);
  25. move_uploaded_file($_FILES['image']['tmp_name'],"images/".$_FILES['image']['name']);
  26. $path ="images/".$_FILES['image']['name'] ;
  27. $imgContent = basename($_FILES['image']['tmp_name']) ;
  28.  
  29. $db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
  30. if($db->connect_error)
  31. {
  32. die("Connection failed: " . $db->connect_error);
  33. }
  34. $insert = $db->query("INSERT into products(product_Image,product_name,Image_path) VALUES ('$imgContent','$image_text','$path' )");
  35. $target = "images/".basename($image);
  36. move_uploaded_file($image, $target) ;
  37.  
  38. if($insert)
  39. {
  40. echo "<center>Image inserted successfully</center>";
  41. }
  42.  
  43. else
  44. echo "<center> Error in inserting image </center>";
  45. }
  46. echo ' </div>';
  47.  
  48. ?>
  49.  
  50. <?php
  51.  
  52. echo '<div class="panel panel-primary">';
  53. echo '<div class="panel-body">';
  54. echo '<form action="" method="post" enctype="multipart/form-data" class="form-horizontal well col-xs-8 col-xs-offset-2">';
  55.  
  56. echo '<input type="text" name="image_text" class="form-control"></input>';
  57.  
  58. echo ' <div class="form-group">';
  59. echo '<input type="file" class="form-control" name="image"/>';
  60. echo ' </div>';
  61.  
  62. echo ' <input type="submit" name="submit" value="Enter" /> ';
  63.  
  64. echo '</form>';
Add Comment
Please, Sign In to add comment