Guest User

Untitled

a guest
Mar 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // connect.php
  2. <?php
  3. $connection = mysqli_connect('localhost', 'root', 'root', 'loginapp');
  4. if(!$connection) {
  5. die("Database connection failed");
  6. }
  7. ?>
  8. // showDb.php
  9. <?php include 'connect.php' ?>
  10. <?php
  11. function showAllData() {
  12. global $connection;
  13. $query = "SELECT * FROM users";
  14. $result = mysqli_query($connection, $query);
  15. if(!$result) {
  16. echo(mysql_error());
  17. }
  18.  
  19. while($row = mysqli_fetch_assoc($result)) {
  20. $id = $row['id'];
  21. echo "<option value='$id'>$id</option>";
  22. }
  23.  
  24. }
  25. ?>
  26. // update.php
  27. <?php include 'showDb.php'; ?>
  28. <?php
  29. if(isset($_POST['sumbit'])) {
  30. $username = $_POST['username'];
  31. $password = $_POST['password'];
  32. $id = $_POST['id'];
  33.  
  34. $query = "UPDATE users SET ";
  35. $query .= "username = '$username', ";
  36. $query .= "password = '$password' ";
  37. $query .= "WHERE id = $id ";
  38.  
  39. $result = mysqli_query($connection, var_dump($query));
  40. if($result) {
  41. echo "Success";
  42. } else {
  43. die(mysql_error());
  44. }
  45. }
  46.  
  47. ?>
  48.  
  49. // some html...
  50. <select name="id" id="">
  51. <?php
  52. showAllData();
  53. ?>
  54. </select>
Add Comment
Please, Sign In to add comment