Advertisement
Guest User

anghirapngweb

a guest
May 2nd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. table
  2. <?php
  3. // Create connection
  4. $conn = new mysqli("localhost:3306", "root", "", "table1");
  5. // Check connection
  6. if ($conn->connect_error) {
  7. die("Connection failed: " . $conn->connect_error);
  8. }
  9.  
  10. $sql = "SELECT * from sample1";
  11. $result = $conn->query($sql);
  12.  
  13. if ($result->num_rows > 0) {
  14. // output data of each row
  15. //echo '<div id="tablediv">';
  16. echo "<table width='850' border='1' cellpadding='1' cellspacing='1'>";
  17. echo "<tr>";
  18. echo "<th>Account ID</th>";
  19. echo "<th>Username</th>";
  20. echo "<th>First Name</th>";
  21. echo "<th>Middle Initial</th>";
  22. echo "<th>Last Name</th>";
  23. echo "<th>Birthday</th>";
  24. echo "<th>Age</th>";
  25. echo "</tr>";
  26. while($row = mysqli_fetch_array($result)){
  27. echo "<tr>";
  28. echo "<td>" . $row['userID'] . "</td>";
  29. echo "<td>" . $row['username'] . "</td>";
  30. echo "<td>" . $row['fname'] . "</td>";
  31. echo "<td>" . $row['mi'] . "</td>";
  32. echo "<td>" . $row['lname'] . "</td>";
  33. echo "<td>" . $row['birthday'] . "</td>";
  34. echo "<td>" . $row['age'] . "</td>";
  35.  
  36. echo "</tr>";
  37. }
  38. echo "</table>";
  39. //echo "</div>";
  40. mysqli_free_result($result);
  41. } else {
  42. echo "0 results";
  43. }
  44. $conn->close();
  45. ?>
  46.  
  47. Find
  48.  
  49. <?php
  50.  
  51. $host = "localhost:3306";
  52. $user = "root";
  53. $password = "";
  54. $database = "table1";
  55.  
  56. $userID = "";
  57. $username = "";
  58. $pass = "";
  59. $fname = "";
  60. $mi = "";
  61. $lname = "";
  62. $birthday = "";
  63. $age = "";
  64.  
  65. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  66.  
  67. try{
  68. $connect = mysqli_connect($host, $user, $password, $database);
  69. }catch (Exception $ex){
  70. echo "Error";
  71. }
  72.  
  73. function getPosts()
  74. {
  75. $posts = array ();
  76. $posts [0] = $_POST['userID'];
  77. $posts [1] = $_POST['username'];
  78. $posts [2] = $_POST['pass'];
  79. $posts [3] = $_POST['fname'];
  80. $posts [4] = $_POST['mi'];
  81. $posts [5] = $_POST['lname'];
  82. $posts [6] = $_POST['birthday'];
  83. $posts [7] = $_POST['age'];
  84. return $posts;
  85. }
  86.  
  87. //search
  88.  
  89. if (isset($_POST['search']))
  90. {
  91. $data = getPosts();
  92.  
  93. $search_Query = "SELECT * FROM Sample1 WHERE userID = $data[0]";
  94.  
  95. $search_Result = mysqli_query($connect, $search_Query);
  96.  
  97. if($search_Result)
  98. {
  99. if(mysqli_num_rows($search_Result))
  100. {
  101. while($row = mysqli_fetch_array($search_Result))
  102. {
  103. $userID = $row ['userID'];
  104. $username = $row ['username'];
  105. $pass = $row ['pass'];
  106. $fname = $row ['fname'];
  107. $mi = $row ['mi'];
  108. $lname = $row ['lname'];
  109. $birthday = $row ['birthday'];
  110. $age = $row ['age'];
  111. }
  112. }else{
  113. echo 'No data for this ID';
  114. }
  115. }else{
  116. echo 'Result Error!';
  117. }
  118. }
  119. ?>
  120. <html>
  121. <body>
  122. <form action="?title=update" method="post" name="formko">
  123. <label>ID:</label>&nbsp;<input type="number" name="userID" value="<?php echo $userID; ?>"/><br><br>
  124. <label>User Name:</label>&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="username" value="<?php echo $username; ?>"/><br><br>
  125. <label>Password:</label>&nbsp;<input type="password" name="pass" value="<?php echo $pass; ?>"/><br><br>
  126. <label>First Name:</label>&nbsp;&nbsp;<input type="text" name="fname" value="<?php echo $fname; ?>"/><br><br>
  127. <label>Middle Initial:</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="mi" value="<?php echo $mi; ?>"/><br><br>
  128. <label>Last Name:</label>&nbsp;<input type="text" name="lname" value="<?php echo $lname; ?>"/><br><br><br>
  129. <label>Birthday:</label>&nbsp;<input type="date" name="birthday" value="<?php echo $birthday; ?>"/><br><br><br>
  130. <label>Age:</label>&nbsp;<input type="text" name="age" value="<?php echo $age; ?>"/><br><br><br>
  131. <div>
  132. </label><input type="Submit" name="insert" value="Add"/>
  133. </label><input type="Reset"name="update" value="Update"/>
  134. </label><input type="Submit"name="delete" value="Delete"/>
  135. <label><input type="Submit"name="search" value="Find"/>
  136. </label><input type="Reset" value="Reset"/>
  137. </div>
  138. </form>
  139. </body>
  140. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement