Jump to content

Confused


Tom8001

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.