Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Group 22!</title>
  6. <meta name="description" content="Oblig 3 DATS2410 - Overview of grades">
  7. <meta name="author" content="David Solheim & Haakon Lien">
  8. <style type="text/css">
  9. table, th, td {
  10. border: 2px solid black;
  11. }
  12.  
  13. table {
  14. border-collapse: collapse;
  15. }
  16.  
  17. td {
  18. text-align: center;
  19. }
  20. a {color:inherit;text-decoration:none;}
  21. footer {position:fixed;bottom:0;}
  22. </style>
  23. </head>
  24. <body>
  25. <?php
  26. if(isset($_POST['delete'])) {
  27. $s_nr=$_POST['snr'];
  28.  
  29. $server = "10.1.1.212";
  30. $username = "maxscale";
  31. $password = "maxscalepass";
  32.  
  33. $conn = new mysqli($server, $username, $password);
  34. if ($conn->connect_error) {
  35. die("Connection failed: " . $conn->connect_error);
  36. }
  37. $sql="USE studentinfosys";
  38. $conn->query($sql);
  39.  
  40. $sql="DELETE FROM students WHERE studentid = \"$s_nr\"";
  41. $conn->query($sql);
  42. $conn->close();
  43. }
  44.  
  45. if (isset($_POST['addNew'])) {
  46. $s_nr=$_POST['snr'];
  47. $fname=$_POST['fname'];
  48. $lname=$_POST['lname'];
  49. $mail=$_POST['email'];
  50. $program=$_POST['program'];
  51. $year=$_POST['year'];
  52.  
  53. $server = "10.1.1.212";
  54. $username = "maxscale";
  55. $password = "maxscalepass";
  56.  
  57. $conn = new mysqli($server, $username, $password);
  58. if ($conn->connect_error) {
  59. die("Connection failed: " . $conn->connect_error);
  60. }
  61. $sql="USE studentinfosys";
  62. $conn->query($sql);
  63.  
  64. $sql="INSERT INTO students (studentid, firstname, lastname, email, studyprogram, startyear) VALUES (\"$s_nr\",\"$fname\",\"$lname\",\"$mail\",\"$program\",\"$year\")";
  65. $conn->query($sql);
  66. $conn->close();
  67. }
  68. ?>
  69. <h1>Welcome to group 22's student management application!</h1>
  70.  
  71. <form method="post">
  72. <h3>Add new student</h3>
  73. <tr>
  74. <td><input type="text" name="snr" placeholder="Student number"</td>
  75. <td><input type="text" name="fname" placeholder="First name"</td>
  76. <td><input type="text" name="lname" placeholder="Last name"</td>
  77. <td><input type="text" name="email" placeholder="Email address"</td>
  78. <td><input type="text" name="program" placeholder="Study program"</td>
  79. <td><input type="text" name="year" placeholder="Start year"</td>
  80. <td><input type="submit" name="addNew" value="Add"</td>
  81. </tr>
  82. </form>
  83.  
  84. <div>
  85. <table style="width:80%;margin-top:10px;margin-bottom:10px;">
  86. <thead>
  87. <tr>
  88. <th>Student number</th>
  89. <th>First name</th>
  90. <th>Last name</th>
  91. <th>Email</th>
  92. <th>Study program</th>
  93. <th>Started</th>
  94. <th>Actions</th>
  95. <th></th>
  96. </tr>
  97. </thead>
  98. <tbody>
  99. <?php
  100. $conn = new mysqli('10.1.1.212', 'maxscale', 'maxscalepass');
  101. if ($conn->connect_error) {
  102. die("Connection failed: " . $conn->connect_error);
  103. }
  104. $sql="USE studentinfosys";
  105. $conn->query($sql);
  106. $sql="SELECT * FROM students";
  107. $result=$conn->query($sql);
  108.  
  109. while($row = $result->fetch_assoc()) {
  110. ?>
  111. <tr>
  112. <td><?php echo $row["studentid"]?></td>
  113. <td><?php echo $row["firstname"]?></td>
  114. <td><?php echo $row["lastname"]?></td>
  115. <td><?php echo $row["email"]?></td>
  116. <td><?php echo $row["studyprogram"]?></td>
  117. <td><?php echo $row["startyear"]?></td>
  118. <td>
  119. <a href="./courses.php?id=<?php echo $row["studentid"]?>"><button type="submit">View Courses</button></a>
  120. <form action="edit.php" method="get">
  121. <input type="hidden" name="snr" value="<?php echo $row["studentid"]?>" />
  122. <input type="submit" name="edit" value="Edit" />
  123. </form>
  124. <form method="post">
  125. <input type="hidden" name="snr" value="<?php echo $row["studentid"]?>" />
  126. <input type="submit" name="delete" value="Delete" />
  127. </form>
  128. </td>
  129. </tr>
  130. <?php
  131. }
  132. $conn->close();
  133. ?>
  134. </tbody>
  135. </table>
  136. </div>
  137.  
  138. <footer>
  139. <p> You are served by this server IP:
  140. <?php
  141. $localIP = getHostByName(getHostName());
  142. echo "$localIP";
  143. ?>
  144. </p>
  145. <p>
  146. You are served by this server:
  147. <?php
  148. $n = getHostName();
  149. echo "$n";
  150. ?>
  151. </p>
  152. <p>
  153. Public IP: 128.39.121.59:8022
  154. </p>
  155. <p>
  156. Database IP:
  157. <?php
  158. $conn = new mysqli('10.1.1.212','maxscale','maxscalepass');
  159. printf($conn->host_info);
  160. $conn->close();
  161. ?>
  162. </p>
  163. </footer>
  164. </body>
  165. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement