A bit stuck, again |
A bit stuck, again |
Jan 14 2010, 09:05 PM
Post
#1
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 |
Hrm, well, I'm setting up a little administrator account privileges and all for my new project, and I have a page for where I can delete users, but, it's not exactly turning out too well. What I have is a while() loop that displays each username and a "clean" version of it for a query string in the URL. So, I was wondering, how could I execute some certain code based on a query string URL that is put in a while() loop?
Here's the code: CODE <?php if (isset($_GET['delete'])) { $delete = $_GET['delete']; } if (!$delete) { // Set Parameters $database['server'] = 'localhost'; $database['username'] = 'username'; $database['password'] = 'password'; $database['name'] = 'database'; // Connect to MySQL Database $connection = mysql_connect($database['server'], $database['username'], $database['password']); mysql_select_db($database['name'], $connection); // Get Usernames $result = mysql_query("SELECT username FROM users"); $number = mysql_num_rows($result); $i = 0; echo '<ul>'; while ($i < $number) { $username = mysql_result($result, $i, 'username'); $clean_username = strtolower($username); echo ' <li><a href="users?delete=' . $clean_username . '">' . $username . '</a></li>'; $i++; } echo ' </ul> <br /> '; } else if ($delete == $clean_username) { mysql_query("DELETE FROM users WHERE username = '$username'"); header ('Location: ' . root . '/account/admin/delete/users'); } else { header ('Location: ' . root . '/account/admin/delete/users'); } ?> I have a feeling it could be a very quick fix. :\ |
|
|
|
Mikeplyts A bit stuck Jan 14 2010, 09:05 PM
mipadi Well, first of all, in general you probably should... Jan 14 2010, 10:10 PM
Mikeplyts ^Hm, well, thanks for the advice. Also, it partial... Jan 14 2010, 10:59 PM
Mikeplyts Oh, I figured out the problem. The MySQL connectio... Jan 17 2010, 02:17 AM
Mike Topic closed & moved. Jan 17 2010, 07:41 AM![]() ![]() |