Advertisement
Guest User

phperror

a guest
Nov 7th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. <?php
  2. // including the database connection file
  3.  
  4. include("config.php");
  5. session_start();
  6. if($_SESSION){
  7. if($_SESSION["rank"] == 2){
  8. if(isset($_POST['update']))
  9. {
  10. $id = $_POST['id'];
  11.  
  12. $username=$_POST['username'];
  13. $email=$_POST['email'];
  14. $password=$_POST['password'];
  15. $rank=$_POST['rank'];
  16.  
  17.  
  18. // checking empty fields
  19. if(empty($username) || empty($email) || empty($password) || empty($rank)) {
  20.  
  21. if(empty($username)) {
  22. echo "<font color='red'>username field is empty.</font><br/>";
  23. }
  24.  
  25. if(empty($email)) {
  26. echo "<font color='red'>email field is empty.</font><br/>";
  27. }
  28.  
  29. if(empty($password)) {
  30. echo "<font color='red'>password field is empty.</font><br/>";
  31. }
  32.  
  33. if(empty($rank)) {
  34. echo "<font color='red'>rank field is empty.</font><br/>";
  35. }
  36. } else {
  37. //updating the table
  38. $sql = "UPDATE users SET username=:username, email=:email, password=:password, rank=:rank WHERE id=:id";
  39. $query = $db->prepare($sql);
  40.  
  41. $query->bindparam(':id', $id);
  42. $query->bindparam(':username', $username);
  43. $query->bindparam(':email', $email);
  44. $query->bindparam(':password', $password);
  45. $query->bindparam(':rank', $rank);
  46. $query->execute();
  47.  
  48. // Alternative to above bindparam and execute
  49. // $query->execute(array(':id' => $id, ':name' => $name, ':email' => $email, ':age' => $age));
  50.  
  51. //redirectig to the display page. In our case, it is admin.php
  52. header("Location: admin.php");
  53. }
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. //getting id from url
  66. $id = $_POST['id'];
  67.  
  68. //selecting data associated with this particular id
  69. $sql = "SELECT * FROM users WHERE id=:id";
  70. $query = $db->prepare($sql);
  71. $query->execute(array(':id' => $id));
  72.  
  73. while($row = $query->fetch(PDO::FETCH_ASSOC))
  74. {
  75. $username = $row['username'];
  76. $email = $row['email'];
  77. $password = $row['password'];
  78. $rank = $rank['rank'];
  79. }
  80. }
  81. else{
  82. echo "alleen voor admins beschikbaar.";
  83. }
  84. }
  85. else{
  86. echo "deze webpagina is niet beschikbaar.";
  87. }
  88. ?>
  89. <html>
  90. <head>
  91. <title>Edit Data</title>
  92. </head>
  93.  
  94. <body>
  95. <a href="admin.php">Home</a>
  96. <br/><br/>
  97.  
  98. <form name="form1" method="post" action="edituser.php">
  99. <table border="0">
  100. <tr>
  101. <td>Name</td>
  102. <td><input type="text" name="username" value="<?php echo $username;?>"></td>
  103. </tr>
  104. <tr>
  105. <td>email</td>
  106. <td><input type="text" name="email" value="<?php echo $email;?>"></td>
  107. </tr>
  108. <tr>
  109. <td>password</td>
  110. <td><input type="text" name="password" value="<?php echo $password;?>"></td>
  111. </tr>
  112. <tr>
  113. <td>rank</td>
  114. <td><input type="text" name="rank" value="<?php echo $rank;?>"></td>
  115. </tr>
  116. <tr>
  117. <td><input type="hidden" name="id" value=<?php echo $_POST['id'];?>></td>
  118. <td><input type="submit" name="update" value="Update"></td>
  119. </tr>
  120. </table>
  121. </form>
  122. </body>
  123. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement