Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="UTF-8">
  4. <title>Group 22!</title>
  5. <meta name="description" content="Oblig 3 DATS2410 - Overview of grades">
  6. <meta name="author" content="David Solheim & Haakon Lien">
  7. <style type="text/css">
  8. table, th, td {
  9. border: 2px solid black;
  10. }
  11.  
  12. table {
  13. border-collapse: collapse;
  14. }
  15.  
  16. td {
  17. text-align: center;
  18. }
  19. footer {position:fixed;bottom:0;}
  20. </style>
  21. </head>
  22. <body>
  23. <a href="./index.php">Go back to the overview of students</a>
  24. <h1>
  25. <?php
  26. if (isset($_GET['snr'])) {
  27. $s_nr=$_GET['snr'];
  28. echo "Edit entry for " . $s_nr;
  29. } else {
  30. echo "Missing student identity. Please try again.";
  31. }
  32. ?></h1>
  33.  
  34. <?php
  35.  
  36. if (isset($_GET['editentry'])) {
  37. #get values
  38. $s_nr=$_GET['snr'];
  39. $fname=$_GET['fname'];
  40. $lname=$_GET['lname'];
  41. $mail=$_GET['email'];
  42. $program=$_GET['program'];
  43. $year=$_GET['year'];
  44.  
  45. #connect
  46. $server = "10.1.1.212";
  47. $username = "maxscale";
  48. $password = "maxscalepass";
  49.  
  50. $conn = mysqli_connect($server, $username, $password);
  51. if ($conn->connect_error) {
  52. die("Connection failed: " . $conn->connect_error);
  53. }
  54. $sql="USE studentinfosys";
  55. $conn->query($sql);
  56.  
  57. $sql="UPDATE students SET studentid=\"$s_nr\", firstname=\"$fname\", lastname=\"$lname\", email=\"$mail\", studyprogram=\"$program\", startyear=\"$year\" WHERE studentid=\"$s_nr\"";
  58. if($conn->query($sql) === TRUE) {
  59. header("Location: ./index.php");
  60. exit;
  61. } else {
  62. echo "<p>Error editing entry: " . $conn->error . "</p>";
  63. }
  64. $conn->close();
  65. }
  66. ?>
  67.  
  68. <form method="get">
  69. <table>
  70. <tr>
  71. <th>Student number</th>
  72. <th>First name</th>
  73. <th>Last name</th>
  74. <th>Email</th>
  75. <th>Study program</th>
  76. <th>Start year</th>
  77. <th>Action</th>
  78. </tr>
  79. <tbody>
  80. <?php
  81. $server = "10.1.1.212";
  82. $username = "maxscale";
  83. $password = "maxscalepass";
  84. $dbname = "studentinfosys";
  85.  
  86. $s_nr = "";
  87. if(isset($_GET['snr'])) {
  88. $s_nr = $_GET['snr'];
  89. }
  90.  
  91. $conn = mysqli_connect($server, $username, $password);
  92. if ($conn->connect_error) {
  93. die("Connection failed: " . $conn->connect_error);
  94. }
  95. $sql="USE studentinfosys";
  96. $conn->query($sql);
  97. $result=$conn->query("SELECT * FROM students WHERE studentid=\"$s_nr\"");
  98.  
  99. while($row = $result->fetch_assoc()) {
  100. ?>
  101. <tr>
  102. <td><input type="text" name="snr" value="<?php echo $row["studentid"]?>" /></td>
  103. <td><input type="text" name="fname" value="<?php echo $row["firstname"]?>" /></td>
  104. <td><input type="text" name="lname" value="<?php echo $row["lastname"]?>" /></td>
  105. <td><input type="text" name="email" value="<?php echo $row["email"]?>" /></td>
  106. <td><input type="text" name="program" value="<?php echo $row["studyprogram"]?>" /></td>
  107. <td><input type="text" name="year" value="<?php echo $row["startyear"]?>" /></td>
  108. <td><input type="submit" name="editentry" value="Edit entry" /></td>
  109. </tr>
  110. <?php
  111. }
  112. $conn->close();
  113. ?>
  114. </tbody>
  115. </table>
  116. </form>
  117.  
  118. <footer>
  119. <p> You are served by this server IP:
  120. <?php
  121. $localIP = getHostByName(getHostName());
  122. echo "$localIP";
  123. ?>
  124. </p>
  125. <p>
  126. You are served by this server:
  127. <?php
  128. $n = getHostName();
  129. echo "$n";
  130. ?>
  131. </p>
  132. <p>
  133. Public IP: 128.39.121.59:8022
  134. </p>
  135. <p>
  136. Database IP:
  137. <?php
  138. $conn = new mysqli('10.1.1.212','maxscale','maxscalepass');
  139. printf($conn->host_info);
  140. $conn->close();
  141. ?>
  142. </p>
  143. </footer>
  144. </body>
  145. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement