Advertisement
Guest User

Untitled

a guest
Feb 4th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <?php
  2.  
  3. $host = "localhost";
  4. $username = "jacobban_week8";
  5. $password = "JzbsOQcU1h5A";
  6. $db = "jacobban_testimonials";
  7.  
  8. $conn = mysqli_connect($host, $username, $password, $db);
  9.  
  10. if(isset($_POST["f_submit"])){
  11. $tName = mysqli_real_escape_string($conn, $_POST["name"]);
  12. $tGender = mysqli_real_escape_string($conn, $_POST["gender"]);
  13. $tTestimonial = mysqli_real_escape_string($conn, $_POST["testimonial"]);
  14. $insert = "INSERT INTO testimonial_tb (gender, name, testimonial) VALUES ('".$tGender."', '".$tName."', '".$tTestimonial."')";
  15. $sendInsert = mysqli_query($conn, $insert);
  16.  
  17. }
  18.  
  19.  
  20. ?>
  21. <div class="page-container">
  22. <?php
  23. $host = "localhost";
  24. $username = "jacobban_week8";
  25. $password = "JzbsOQcU1h5A";
  26. $db = "jacobban_testimonials";
  27.  
  28. $conn = mysqli_connect($host, $username, $password, $db);
  29.  
  30. if(!$conn){
  31. echo "<p>Connection failed</p>";
  32. }
  33. else{
  34.  
  35. $query = "SELECT * FROM testimonial_tb";
  36.  
  37. $queryResult = mysqli_query($conn, $query);
  38.  
  39. $numRows = mysqli_num_rows($queryResult);
  40.  
  41. if($numRows > 0){
  42. echo "<table>";
  43. echo "<tr> <th>Name</th> <th>Gender</th> <th>Testimonial</th> </tr>";
  44.  
  45. while($row = mysqli_fetch_assoc($queryResult)){
  46. $gender = $row["gender"];
  47. $name = $row["name"];
  48. $testimonial = $row["testimonial"];
  49.  
  50. echo "<tr>";
  51. echo "<td>" . $name . "</td>";
  52. echo "<td>" . $gender . "<td>";
  53. echo "<td>" . $testimonial . "</td>";
  54. echo "</tr>";
  55.  
  56. }
  57. echo "</table>";
  58. }
  59. }
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement