Looking for ideas on this code...
Posted: Mon Apr 28, 2003 8:28 pm
I've recently just tried programming in PHP and being completely new to it I've run into a problem here and there but nothing I couldn't work through. Now I've got this problem, I don't know whether it is through coding, or through my approach and I would appreciate any ideas/comments.
Here's my situation, I've been working on a site where members log in and then are assigned a userlevel either 1-4, 1 being the user with the most access to things. What I've been working on now is a script to promote users and demote users. I created a page that calls all my users from a database and then displays them in a table each user in a different row with each row having the option to promote/demote. I wrote the following script, thinking it would work properly:
My dilemma is that when I try to promote one user, it promotes them all, and vice versa. Is it my code, or do I need to try a different approach? Thanks for your time and any comments.
Here's my situation, I've been working on a site where members log in and then are assigned a userlevel either 1-4, 1 being the user with the most access to things. What I've been working on now is a script to promote users and demote users. I created a page that calls all my users from a database and then displays them in a table each user in a different row with each row having the option to promote/demote. I wrote the following script, thinking it would work properly:
Code: Select all
<FORM ACTION="<?PHP_SELF?>" METHOD="Post">
<INPUT TYPE="submit" name="promote" VALUE="Promote">
</FORM>
<?
$puserlevel = $tuserlevel - 1;
if($promote)
{
$connection = mysql_connect($DBhost, $DBuser, $DBpass) or die ("Unable to connect!");
mysql_select_db($DBName) or die ("Unable to select database!");
$query = "UPDATE auth_user SET userlevel = '$puserlevel' WHERE username ='$tusername'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
}
?>