Guest User

Untitled

a guest
Jun 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. <?php
  2. $db = mysqli_connect('localhost', 'root', '(Password)', 'web');
  3. #THE 'userEmail' variable is from a script above not displayed on here
  4. $email = $row['userEmail'];
  5. $result = mysqli_query($db, "SELECT * FROM table WHERE email = '$email'");
  6.  
  7. echo "<center><table border='1'>
  8.  
  9. <tr>
  10. <th>Username</th>
  11. <th>Password</th>
  12. <th>Active?</th>
  13. <th>Add Account</th>
  14. <th>Delete Account</th>
  15. </tr>";
  16.  
  17. while($row = mysqli_fetch_array($result))
  18. {
  19.  
  20. $userName = $row['username'];
  21. $passWord = $row['password'];
  22. $addId = $row['id'];
  23. $deleteId = $row['id'];
  24. echo "<tr>";
  25. echo "<td>" . $row['username'] . "</td>";
  26. echo "<td>" . $row['password'] . "</td>";
  27. echo "<td>" . $row['activeStatus'] . "</td>";
  28. echo "<td><a href=home.php?add=$addId>Add Account</a></td>";
  29. echo "<td><a href=home.php?delete=$deleteId>Delete Account</a></td>";
  30. echo "</tr>";
  31. }
  32. echo "</table></center>";
  33.  
  34. if( isset($_GET['delete']) ) {
  35. $deleteId = $_GET['delete'];
  36. $delete = "DELETE FROM table WHERE id = $deleteId";
  37. $result = mysqli_query($db, $delete);
  38. deleteLineInFile("/var/www/html/table-users.txt","'$userName'");
  39. if ($result == TRUE) {
  40. echo "Record updated successfully";
  41. header('Location: home.php');
  42. } else {
  43. echo "Error updating record";
  44. }
  45. }
  46.  
  47. if( isset($_GET['add']) ) {
  48. $addId = $_GET['add'];
  49. $add = "(Too long to display)";
  50.  
  51. echo("$userName, $passWord");
  52.  
  53. file_put_contents("/var/www/html/directory/$addId.xml", $add);
  54. header("Location: directory/$addId.xml");
  55.  
  56. }
  57.  
  58. function deleteLineInFile($file,$string)
  59. {
  60. $i=0;$array=array();
  61.  
  62. $read = fopen($file, "r") or die("can't open the file");
  63. while(!feof($read)) {
  64. $array[$i] = fgets($read);
  65. ++$i;
  66. }
  67. fclose($read);
  68.  
  69. $write = fopen($file, "w") or die("can't open the file");
  70. foreach($array as $a) {
  71. if(!strstr($a,$string)) fwrite($write,$a);
  72. }
  73. fclose($write);
  74. }
  75. ?>
Add Comment
Please, Sign In to add comment