Jump to content

Problem with users


Tom8001
Go to solution Solved by Barand,

Recommended Posts

I have used 

$sql = "SELECT id, username FROM $tbl_name ORDER BY username";
$result = $con->query($sql);
while ($row = $result->fetch_assoc())
{
    echo "<a href='editUser.php?id={$row['id']}'>{$row['username']}</a><br><br>\n";
    echo "<style>a {color: blue; text-decoration: none;} a:hover {color: #ff0000} body {background-color: #000;} </style>";
}

in euser.php which echo's out all the users in the database via an anchor tag and includes their id in the url.

but when i click on their name i want to have options like:

- change password

- ban user

e.t.c

and i have tried 

$sql = "SELECT id FROM $tbl_name";
$result = $con->query($sql);
while ($row = $result->fetch_assoc()) {

echo "<a href='editUser.php?id={$row['id']}'> Change Password  </a>

in my other page editUser.php

it posts Change Password Change Password Change Password and each change password has the 3 ids of the users

 

this is confusing me.

Link to comment
Share on other sites

I know but, in the file euser.php it looks like this 

 

479024075299cab76e393875838f326d.png

 

And editUser.php looks like this

 

253435e3b71796272af53310052e3ffb.png

 

 

Now the 3 change password links are each for a user, when i only want a change password link with the current users id that i have clicked on, if that makes any sense?

Link to comment
Share on other sites

Define you styles once in the <head>..</head> section of your page, not every time you output something to the page. eg

<html>
<head>
<style>
a {
    color: blue; 
    text-decoration: none;
} 
a:hover {
    color: #ff0000;
} 
body {
    background-color: #000;
} 
</style>
</head>

or put the styles in an external .css file.

 

Having linked to "edituser.php?id=1" passing the id of the selected user, why would you then run a query to get the ids of all the users again? Get the details of the selected user for editing (ie. change password, set a flag to ban them etc.)

Link to comment
Share on other sites

 

 

Having linked to "edituser.php?id=1" passing the id of the selected user, why would you then run a query to get the ids of all the users again? Get the details of the selected user for editing (ie. change password, set a flag to ban them etc.)

Because i wanted 

- change password

- ban user

e.t.c 

 

to be links 

 

for example

<a href='changepwd.php'>  Change Password  </a>

if i was to click this while browsing editUser.php?id=1 , The user would not longer be selected

Link to comment
Share on other sites

  • Solution

Perhaps this in euser.php

$sql = "SELECT id, username FROM $tbl_name ORDER BY username";
$result = $con->query($sql);

echo "<table cellpadding='5'>";
while ($row = $result->fetch_assoc())
{
    echo "<tr><td>{$row['username']}</td>
        <td><a href='editUser.php?id={$row['id']}'>Edit User</a></td>
        <td><a href='changepassword.php?id={$row['id']}'>Change Password</a></td>
        <td><a href='banUser.php?id={$row['id']}'>Ban User</a></td>
        </tr>\n";
}
echo "</table>\n";

  • Like 1
Link to comment
Share on other sites

 

Perhaps this in euser.php

$sql = "SELECT id, username FROM $tbl_name ORDER BY username";
$result = $con->query($sql);

echo "<table cellpadding='5'>";
while ($row = $result->fetch_assoc())
{
    echo "<tr><td>{$row['username']}</td>
        <td><a href='editUser.php?id={$row['id']}'>Edit User</a></td>
        <td><a href='changepassword.php?id={$row['id']}'>Change Password</a></td>
        <td><a href='banUser.php?id={$row['id']}'>Ban User</a></td>
        </tr>\n";
}
echo "</table>\n";

Thanks so much!

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.