Advertisement
Guest User

Edit1

a guest
Jun 3rd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <html><head></head>
  2. <body>
  3.  
  4. <form method="post" action="" enctype="multipart/form-data">
  5.  
  6.     Upload File:
  7.     <input type="file" name="upload" /><br>
  8.     <input type="submit" name="submit" value="Submit"/>
  9. </form>
  10. </body>
  11. </html>
  12. <?php
  13.     $servername ="localhost";
  14.     $username = "root";
  15.     $password = "";
  16.     $dbname = "produ_db";
  17.  
  18. // Create connection
  19. $conn = mysqli_connect($servername, $username, $password, $dbname);
  20. // Check connection
  21. if (!$conn) {
  22.     die("Connection failed: " . mysqli_connect_error());
  23. }
  24. if(isset($_POST['submit'])  ){
  25.     if ($_FILES['upload']['name'] == 0 ){
  26.         $filename = $conn->real_escape_string($_FILES['upload']['name']);
  27.         $filedata= $conn->real_escape_string(file_get_contents($_FILES['upload']['tmp_name']));
  28.             echo "Error: unable to store image";
  29. }
  30.  
  31. else {
  32.     /*where acc_cap is the image caption && acc_img is a blob type to store images*/
  33.     $query = "INSERT INTO accessories(`acc_cap`,`acc_img`) VALUES ('$filename','$filedata')" ;
  34.     if ($conn->query($query) === TRUE) {
  35.     echo "<br><br> New record created successfully";
  36.     } else {
  37.     echo "Error:<br>" . $conn->error;
  38.     }
  39.  
  40. }
  41. $conn->close();
  42. }  
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement