Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <form action="insert2.php" method="GET" enctype="multipart/form-data">
  2. <div class="container">
  3. <div class="row">
  4. <h2>3. Description of Item(s) </h2>
  5. </div>
  6.  
  7. <div class="col-xs-12">
  8. <div class="styled-input wide">
  9. <textarea name="description" required /></textarea>
  10. </div>
  11. // this is the file attachment where it allows to select file from computer.
  12. <div>
  13. <label>Attachment:</label><input type='file' name='img' ><br>
  14.  
  15. </div>
  16. </div>
  17.  
  18. </form>
  19.  
  20. $con= mysqli_connect('127.0.0.1','root','');
  21.  
  22. if(!$con)
  23. {
  24. echo 'Not Connected To Server';
  25. }
  26.  
  27. if(!mysqli_select_db($con,'satsform1'))
  28. {
  29. echo 'Database Not Selected';
  30. }
  31.  
  32. $description = $_GET['description'];
  33. $image = $_GET['img'];
  34.  
  35. //insert image to database.
  36.  
  37. $sql = "INSERT INTO handover (description,image)
  38. VALUES ('$description','$image')";
  39.  
  40. if(!mysqli_query($con,$sql))
  41. {
  42. echo 'Not Submitted';
  43. }
  44. else
  45. {
  46. echo 'Submitted';
  47. }
  48.  
  49. header("refresh:2; url=selection.php")
  50.  
  51. ?>
  52.  
  53. <?php
  54. $connect = mysqli_connect('127.0.0.1','root','', 'satsform1');
  55. $output = '';
  56. if(isset($_POST["query"]))
  57. {
  58. $search = mysqli_real_escape_string($connect, $_POST["query"]);
  59. $query = "
  60. SELECT * FROM handover
  61. WHERE name LIKE '%".$search."%'
  62. OR staffno LIKE '%".$search."%'
  63. OR date LIKE '%".$search."%'
  64. OR email LIKE '%".$search."%'
  65. ";
  66. }
  67. else
  68. {
  69. $query = "
  70. SELECT * FROM handover ORDER BY ID
  71. ";
  72. }
  73. $result = mysqli_query($connect, $query);
  74. if(mysqli_num_rows($result) > 0)
  75. {
  76. $output .= '
  77. <div class="table-responsive">
  78. <table class="table table bordered">
  79. <tr>
  80. <th>ID</th>
  81. <th>Image</th>
  82. </tr>
  83. ';
  84. while($row = mysqli_fetch_array($result))
  85. {
  86. $output .= '
  87. <tr>
  88. <td>'.$row["ID"].'</td>
  89.  
  90. <td>'.$row["img"].'</td>
  91. </tr>
  92. ';
  93. }
  94. echo $output;
  95. }
  96. else
  97. {
  98. echo 'Data Not Found';
  99. }
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement