Log In · Register

 
A bit stuck, again
Mikeplyts
post 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');
}
?>


mellow.gif

I have a feeling it could be a very quick fix. :\
 
 
Start new topic
Replies
Mikeplyts
post Jan 14 2010, 10:59 PM
Post #2


Mel Blanc was allergic to carrots.
*******

Group: Official Designer
Posts: 6,371
Joined: Aug 2008
Member No: 676,291



^Hm, well, thanks for the advice. Also, it partially worked and by partially, I mean that the user actually doesn't get deleted from the database. Something with the MySQL query, or what?

I added a little echo statement under the MySQL query to echo the ID number that was deleted, yet the user with that ID number wasn't deleted at all. mellow.gif
 

Posts in this topic


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: