Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. <?php define('ISITSAFETORUN', TRUE);
  2. $mytable="tp4364";//set a variable for the database table
  3.  
  4. error_reporting(E_ALL);
  5. ?>
  6.  
  7. <!DOCTYPE html>
  8. <html lang="en">
  9. <head>
  10. <meta charset="UTF-8" >
  11. <title> Erehwon Guest House </title>
  12. <link rel="stylesheet" type="text/css" href="style2.css" />
  13. </head>
  14. <body>
  15. <h1 id="title">Erehwon Guest House</h1>
  16.  
  17. <?php
  18.  
  19. if (!empty($_POST))
  20. {
  21. foreach ($_POST as $key => $value)
  22. {
  23. if ( is_array( $value )){
  24. foreach ($value as $cbkey => $cbvalue)
  25. {
  26. $webdata[$key.$cbkey] = $cbvalue;
  27. }
  28. } else{
  29.  
  30. $webdata[$key] = $value;
  31. }
  32. }
  33. } else{
  34. }
  35. ?>
  36.  
  37. <?php
  38. //connect to this host
  39. require "mydatabase.php";
  40. $dbhandle = mysqli_connect( $hostname, $username, $password ) or die( "Unable to connect to MySQL");
  41. ?>
  42.  
  43.  
  44.  
  45. <div id="currentCon">
  46. <?php
  47. //select database
  48. $selected = mysqli_select_db( $dbhandle, $mydatabase ) or die("Unable to connect to " . $mydatabase );
  49. echo "<p>Connected to database {$mydatabase}</p>"
  50. ?>
  51. </div>
  52.  
  53. <?php
  54. $thisquery = "SHOW TABLES FROM " . $mydatabase ;
  55. $result = mysqli_query( $dbhandle, $thisquery ) or die (" Could not action the query " . $thisquery );
  56. while ($row = mysqli_fetch_array($result)) {
  57. }
  58. ?>
  59.  
  60. <?php
  61. if (isset($webdata['firstname'] ) && !empty($webdata['firstname'] )){
  62. $sql = "INSERT INTO tp4364 (firstname, lastname, email, comments) VALUES ('{$webdata['firstname']}','{$webdata['lastname']}','{$webdata['email']}','{$webdata['comments']}')";
  63.  
  64. if (mysqli_query($dbhandle, $sql)) {
  65. echo "New record created successfully";
  66. } else {
  67. echo "Error: " . $sql . "<br>" . mysqli_error($dbhandle);
  68. }
  69. }
  70. ?>
  71.  
  72. <p class="headers">Current Contents</p>
  73. <table id="cssTable" border=1 cellpadding=1 cellspacing=1>
  74. <tr>
  75. <th>ID</th>
  76. <th>First Name</th>
  77. <th>Last Name</th>
  78. <th>Email</th>
  79. <th id="comment">Comment</th>
  80. <th>Delete</th>
  81.  
  82. </tr>
  83. <?php
  84. $sql = "SELECT id, firstname, lastname, email, comments FROM tp4364";
  85. $result = mysqli_query($dbhandle, $sql);
  86. if ($result->num_rows > 0) {
  87. while($row = $result->fetch_assoc()) {
  88. echo "<tr>";
  89. echo "<td>".$row["id"]."</td>";
  90. echo "<td>".$row["firstname"]."</td>";
  91. echo "<td>".$row["lastname"]."</td>";
  92. echo "<td>".$row["email"]."</td>";
  93. echo "<td>".$row["comments"]."</td>";
  94. echo "<td><a href=delete2.php?id=".$row["id"].">Delete</a></td>";
  95.  
  96. }
  97. } else {
  98. echo "0 results";
  99. }
  100. ?>
  101. </table>
  102.  
  103. <div id="dataform">
  104. <div id="form">
  105. <h2 class="headers1">Enter a new record:</h2>
  106. <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" name = "tp4364form" >
  107.  
  108. <div class="label"><label for="firstname">First name: </label></div><p>
  109. <div><input class="textinput" type="text" name="firstname" id="firstname" placeholder="firstname" required maxlength="30" minlength="1" value="" ></div>
  110.  
  111. <div class="label"><p><label for="lastname">Last name: </label></div><p>
  112. <div><input class="textinput" type="text" name="lastname" id="lastname" pattern="[a-zA-Z0-9.-]+" placeholder="lastname" required maxlength="30" minlength="1" value=""> </div>
  113.  
  114. <div class="label"><p><label for="email">Email: </label></div><p>
  115. <div><input class="textinput" type="text" name="email" id="email" placeholder="email" maxlength="50" minlength="4" value="" ></p></div><p>
  116.  
  117. <div class="label"><p><label for="comments">Comments: </label></div><p>
  118. <div><textarea class="textinput" name="comments" ROWS=6 COLS=60 id="comments" placeholder="comments" maxlength="65000" minlength="1" value="" >
  119. </textarea></div>
  120. </p>
  121.  
  122. <p><label for="submit"></label><input type="submit" name="submit" id="submit" value="Submit New"></p>
  123. </form>
  124. </div
  125.  
  126. </div>
  127.  
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement