Guest User

Untitled

a guest
Oct 26th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "password";
  5. $dbname = "myDB";
  6. $tbname = "myVis";
  7. // Create connection
  8. $conn = mysqli_connect($servername, $username, $password, $dbname);
  9. // Check connection
  10. if (!$conn) {
  11. die("Connection failed: " . mysqli_connect_error());
  12. }
  13.  
  14. $sql = "SELECT * FROM " . $tbname . " WHERE id = '$_POST[id]'";
  15. $result = mysqli_query($conn, $sql);
  16.  
  17. if (mysqli_num_rows($result) > 0) {
  18.  
  19. while($row = mysqli_fetch_assoc($result)) {
  20. $id = $row['id'];
  21. $firstname = $row['firstname'];
  22. $lastname = $row['lastname'];
  23. $image = $row['image'];
  24. $course = $row['course'];
  25. $frdate = $row['frdate'];
  26. $todate = $row['todate'];
  27. $email = $row['email'];
  28. $checkout = $row['checkout'];
  29. }
  30. }
  31. mysqli_close($conn);
  32. ?>
  33. <!DOCTYPE html>
  34. <html lang="en">
  35. <head>
  36. <meta charset="UTF-8">
  37. ...
  38. </head>
  39. <body>
  40.  
  41. <form action='' method='post'>
  42. <table>
  43. ...
  44. <tr>
  45. <td>Efternamn:</td>
  46. <td>
  47. <input id="lastname2" type="text" value='<?php echo $lastname; ?>' /></td>
  48. </tr>
  49. ...
  50. </table>
  51.  
  52. <?php
  53. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  54. if (isset($_POST['submit2'])) {
  55. ...
  56. if (isset($_POST['lastname2'])) {
  57. $lastname = $_POST['lastname2'];
  58. }
  59. ...
  60. $servername = "localhost";
  61. $username = "root";
  62. $password = "password";
  63. $dbname = "myDB";
  64. $tbname = "myVis";
  65. // Create connection
  66. $conn = mysqli_connect($servername, $username, $password, $dbname);
  67. // Check connection
  68. if (!$conn) {
  69. die("Connection failed: " . mysqli_connect_error());
  70. }
  71. $sql2 = "UPDATE " . $tbname . " SET firstname='$firstname', lastname='$lastname', image='$image', course='$course', frdate='$frdate', todate='$todate', email='$email', checkout='$checkout' WHERE id ='".$_POST['id']."'";
  72. $result = mysqli_query($conn, $sql2);
  73. if ($result) {
  74. echo "Record updated successfully";
  75. } else {
  76. echo "Error updating record: " . mysqli_error($conn);
  77. }
  78.  
  79. mysqli_close($conn);
  80. }
  81. }
  82. ?>
  83.  
  84. <input type="submit" name="submit2" id="submit2" value="Spara" />
  85. <input type="button" name="back" id="back" value="Tillbaka" onclick="history.back()" />
  86.  
  87. </form>
  88. </body>
  89. </html>
Add Comment
Please, Sign In to add comment