Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = mysqli_connect('localhost', 'root', '(Password)', 'web');
- #THE 'userEmail' variable is from a script above not displayed on here
- $email = $row['userEmail'];
- $result = mysqli_query($db, "SELECT * FROM table WHERE email = '$email'");
- echo "<center><table border='1'>
- <tr>
- <th>Username</th>
- <th>Password</th>
- <th>Active?</th>
- <th>Add Account</th>
- <th>Delete Account</th>
- </tr>";
- while($row = mysqli_fetch_array($result))
- {
- $userName = $row['username'];
- $passWord = $row['password'];
- $addId = $row['id'];
- $deleteId = $row['id'];
- echo "<tr>";
- echo "<td>" . $row['username'] . "</td>";
- echo "<td>" . $row['password'] . "</td>";
- echo "<td>" . $row['activeStatus'] . "</td>";
- echo "<td><a href=home.php?add=$addId>Add Account</a></td>";
- echo "<td><a href=home.php?delete=$deleteId>Delete Account</a></td>";
- echo "</tr>";
- }
- echo "</table></center>";
- if( isset($_GET['delete']) ) {
- $deleteId = $_GET['delete'];
- $delete = "DELETE FROM table WHERE id = $deleteId";
- $result = mysqli_query($db, $delete);
- deleteLineInFile("/var/www/html/table-users.txt","'$userName'");
- if ($result == TRUE) {
- echo "Record updated successfully";
- header('Location: home.php');
- } else {
- echo "Error updating record";
- }
- }
- if( isset($_GET['add']) ) {
- $addId = $_GET['add'];
- $add = "(Too long to display)";
- echo("$userName, $passWord");
- file_put_contents("/var/www/html/directory/$addId.xml", $add);
- header("Location: directory/$addId.xml");
- }
- function deleteLineInFile($file,$string)
- {
- $i=0;$array=array();
- $read = fopen($file, "r") or die("can't open the file");
- while(!feof($read)) {
- $array[$i] = fgets($read);
- ++$i;
- }
- fclose($read);
- $write = fopen($file, "w") or die("can't open the file");
- foreach($array as $a) {
- if(!strstr($a,$string)) fwrite($write,$a);
- }
- fclose($write);
- }
- ?>
Add Comment
Please, Sign In to add comment