Tom8001 Posted December 4, 2014 Share Posted December 4, 2014 Hi, i'm about to start making my admin page for my site and i'm confused on if i wanted to select a user to change the password or ban them e.t.c how would i select the user? so like if i had a list of all the users on my web page i.e John Paul Lisa how would i select one of them so i could make changes? Quote Link to comment Share on other sites More sharing options...
jcbones Posted December 4, 2014 Share Posted December 4, 2014 Select them through an anchor, passing the id through the the uri, and receiving the id back through the $_GET array. Then you can display the user on the receiving page. Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 4, 2014 Author Share Posted December 4, 2014 I don't understand how you can get the specified user name / id through an anchor tag Quote Link to comment Share on other sites More sharing options...
CroNiX Posted December 4, 2014 Share Posted December 4, 2014 http://yoursite.com/user.php?uid=4 //pass uid=4 as a GET parameter to the user.php script in user.php $user_id = $_GET['uid']; 1 Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 4, 2014 Author Share Posted December 4, 2014 http://yoursite.com/user.php?uid=4 //pass uid=4 as a GET parameter to the user.php script in user.php $user_id = $_GET['uid']; what i'm saying though is like lets say i sent a query to the database and i was to echo out all the users in the database. They would just come out as plain text and want i want to know is how can i actually make it so i can click on the username and get the user id? Quote Link to comment Share on other sites More sharing options...
gizmola Posted December 4, 2014 Share Posted December 4, 2014 When you do a query, you fetch the results in your server side script. Each row is going to have an id column, correct? Your script returns output in the form of html. It is up to you to determine what the form of that output would be. For something like this, a typical response would be in the form of a table with different columns. Often people will include a column with one or more buttons like "ban", "edit", "password". The buttons can be simple url's of the type Cronix just described. You simply need to write the scripts for each of the functions, or perhaps a master script that took multiple parameters like: user.php?uid=4&mode=ban Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 4, 2014 Share Posted December 4, 2014 Tom, Exactly what coding have you done previously? I have a feeling you have dove very little PHP coding, especially with using a database. We're happy to help, but this forum is primarily for people to get help with code they have written. I get the feeling this thread is going to turn into a tutorial on basic programming logic. But, I'll be generous and give you a basic example. If you don't understand this, then you really need to do some work to learn the basics. But, definitely come here when you have specific questions. selectUser.php (create a list of users as links to edit them) $sql = "SELECT user_id, user_name FROM users ORDER BY user_name"; $result = $mysqli->query($sql); while ($row = $result->fetch_assoc()) { echo "<a href='editUser.php?id={$row['user_id']}'>{$row['user_name']}</a><br>\n"; } editUser.php (Page to display data about a user and edit them $userID = $_GET['id']; //Run query using the user ID to get their current attributes and provide controls to edit Quote Link to comment Share on other sites More sharing options...
Tom8001 Posted December 4, 2014 Author Share Posted December 4, 2014 Tom, Exactly what coding have you done previously? I have a feeling you have dove very little PHP coding, especially with using a database. We're happy to help, but this forum is primarily for people to get help with code they have written. I get the feeling this thread is going to turn into a tutorial on basic programming logic. But, I'll be generous and give you a basic example. If you don't understand this, then you really need to do some work to learn the basics. But, definitely come here when you have specific questions. selectUser.php (create a list of users as links to edit them) $sql = "SELECT user_id, user_name FROM users ORDER BY user_name"; $result = $mysqli->query($sql); while ($row = $result->fetch_assoc()) { echo "<a href='editUser.php?id={$row['user_id']}'>{$row['user_name']}</a><br>\n"; } editUser.php (Page to display data about a user and edit them $userID = $_GET['id']; //Run query using the user ID to get their current attributes and provide controls to edit ah no, i understand it, it's because i have never done this exact thing before i was confused on how i was to go about doing it, but no thanks that did help. 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.