Advertisement
Guest User

Untitled

a guest
Feb 3rd, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <?php include("include/header.php"); ?>
  6.  
  7. <title></title>
  8. </head>
  9. <body>
  10. <?php include("include/nav.php"); ?>
  11.  
  12. <form action="<?php echo htmlentities( $_SERVER[ 'PHP_SELF' ] ); ?>" method="POST">
  13. <input type="input" name="name" placeholder="Enter Name"/>
  14. <input type="input" name="gender" placeholder="Enter Gender"/>
  15. <input type="text" name="testimonial" placeholder="Enter testimonial"/>
  16. <input type="submit" name="f_submit" value="Submit Testimonial"/>
  17. </form>
  18.  
  19. <?php
  20.  
  21. $host = "localhost";
  22. $username = "root";
  23. $password = "";
  24. $db = "testimonial_db";
  25.  
  26. $conn = mysqli_connect($host, $username, $password, $db);
  27.  
  28. if(isset($POST_["f_submit"])){
  29. $tName = mysqli_real_escape_string($conn, $_POST["name"]);
  30. $tGender = mysqli_real_escape_string($conn, $_POST["gender"]);
  31. $tTestimonial = mysqli_real_escape_string($conn, $_POST["testimonial"]);
  32. $insert = "INSERT INTO testimonial_tb (gender, name, testimonial) VALUES ('".$tGender."', '".$tName."', '".$tTestimonial."')";
  33. $sendInsert = mysqli_query($conn, $insert);
  34.  
  35. echo "<p>Testimonial Added</p>";
  36.  
  37. }
  38.  
  39. ?>
  40.  
  41. <?php
  42. $host = "localhost";
  43. $username = "root";
  44. $password = "";
  45. $db = "testimonial_db";
  46.  
  47. $conn = mysqli_connect($host, $username, $password, $db);
  48.  
  49. if(!$conn){
  50. echo "<p>Connection failed</p>";
  51. }
  52. else{
  53.  
  54. $query = "SELECT * FROM testimonial_tb";
  55.  
  56. $queryResult = mysqli_query($conn, $query);
  57.  
  58. $numRows = mysqli_num_rows($queryResult);
  59.  
  60. if($numRows > 0){
  61. echo "<table>";
  62. echo "<tr> <th>Name</th> <th>Gender</th> <th>Testimonial</th> </tr>";
  63.  
  64. while($row = mysqli_fetch_assoc($queryResult)){
  65. $gender = $row["gender"];
  66. $name = $row["name"];
  67. $testimonial = $row["testimonial"];
  68.  
  69. echo "<tr>";
  70. echo "<td>" . $name . "</td>";
  71. echo "<td>" . $gender . "<td>";
  72. echo "<td>" . $testimonial . "</td>";
  73. echo "</tr>";
  74.  
  75. }
  76. echo "</table>";
  77. }
  78. }
  79. ?>
  80.  
  81. <!-- <form action="<?php //echo htmlentities( $_SERVER[ 'PHP_SELF' ] ); ?>" method="POST">
  82. <input type="input" name="name" placeholder="Enter Name"/>
  83. <input type="input" name="gender" placeholder="Enter Gender"/>
  84. <input type="text" name="testimonial" placeholder="Enter testimonial"/>
  85. <input type="submit" name="f_submit" value="Submit Testimonial"/>
  86. </form> -->
  87.  
  88. <?php
  89.  
  90. /*$host = "localhost";
  91. $username = "root";
  92. $password = "";
  93. $db = "testimonial_db";
  94.  
  95. $conn = mysqli_connect($host, $username, $password, $db);
  96.  
  97. if(isset($POST_["f_submit"])){
  98. $tName = mysqli_real_escape_string($conn, $_POST["name"]);
  99. $tGender = mysqli_real_escape_string($conn, $_POST["gender"]);
  100. $tTestimonial = mysqli_real_escape_string($conn, $_POST["testimonial"]);
  101. $insert = "INSERT INTO testimonial_tb (gender, name, testimonial) VALUES ('".$tGender."', '".$tName."', '".$tTestimonial."')";
  102. $sendInsert = mysqli_query($conn, $insert);
  103.  
  104. echo "<p>Testimonial Added</p>";
  105. }
  106. */
  107.  
  108.  
  109.  
  110. ?>
  111.  
  112. </body>
  113. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement