A bit stuck, again |
A bit stuck, again |
![]()
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. :\ |
|
|
![]() |
![]()
Post
#2
|
|
![]() Mel Blanc was allergic to carrots. ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Official Designer Posts: 6,371 Joined: Aug 2008 Member No: 676,291 ![]() |
Oh, I figured out the problem. The MySQL connection was in the if statement, and not in the else so the MySQL query couldn't be executed because there was no connection to start with. Solved by simply placing the connection outside of each statement to be used "globally".
Excuse the double post, by the way, but this topic may be closed now. |
|
|
![]() ![]() |