Tom8001 Posted November 25, 2014 Share Posted November 25, 2014 Hey, So i have an admin.php page that lists all of the users in the database and im wondering how i can add functions so the administrator can delete / ban the user from the webpage i'm not sure on how you would select the user? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 25, 2014 Share Posted November 25, 2014 You select the user by their ID (whatever that is). How exactly the ID is passed to the server depends on your GUI. Is there a “ban” and “delete” button next to each user in the list? Is there an extra page for editing a specific user? Either way, be very careful about Cross-Site Request Forgery. If you just accept any request coming from an admin, then it's easy for a malicious website to forge requests and ban or delete arbitrary users. You need to include a special random token in each request (see Synchronizer Token Pattern). You also shouldn't actually delete users, because people may click the button by accident. There's also a big risk of ending up with broken references. Instead, mark the user as deleted. Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted November 25, 2014 Author Share Posted November 25, 2014 No, i'm just echoing the users out. Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted November 25, 2014 Author Share Posted November 25, 2014 i have a ban system in place and i have user levels Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted November 25, 2014 Share Posted November 25, 2014 Yes, I understand that. But the question was how your GUI looks like. Is there a “ban” button next to each user in the list? 1 Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted November 25, 2014 Author Share Posted November 25, 2014 Yes, I understand that. But the question was how your GUI looks like. Is there a “ban” button next to each user in the list? Nope Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted November 25, 2014 Author Share Posted November 25, 2014 I can link you the files if you want? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted November 26, 2014 Share Posted November 26, 2014 Tom, There are about a million and maybe more ways to do this. What do you want regarding the user experience? A link next to each user? A select menu to select the user? An autocomplete to select the user? A checkbox next to each user? Or something else? Once you decide on this, there are many ways to implement, however, fortunately less than a million. Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted November 26, 2014 Author Share Posted November 26, 2014 Tom, There are about a million and maybe more ways to do this. What do you want regarding the user experience? A link next to each user? A select menu to select the user? An autocomplete to select the user? A checkbox next to each user? Or something else? Once you decide on this, there are many ways to implement, however, fortunately less than a million. Ok so i have a query that gets all the usernames from the database and i have echoed them out. i want make a button next to it that can ban / unban the user but what i am confused about is how would i select that user? Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted November 26, 2014 Solution Share Posted November 26, 2014 Ok so i have a query that gets all the usernames from the database and i have echoed them out. i want make a button next to it that can ban / unban the user but what i am confused about is how would i select that user? What do you mean by "Select" the user? You just stated you are echoing out the list of users and you want a button next to each. There is no "selection". Just make each button an individual form which includes a hidden field with the id of the user. while($row = $sth->fetch(PDO::FETCH_ASSOC)) { echo "Username: {$row['username']} "; echo "<form action='ban.php' method='post'>"; echo " <hidden name='id' value='{$row['user_id']}'>\n"; echo " <button type='submit'>Ban user</button>"; echo "</form><br><br>"; } 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.