Jump to content

[SOLVED] Converting Member_Type Member to Admin


Ell20

Recommended Posts

Hey guys,

 

Im trying to add an Admin feature where the admin can select a member to convert to an admin.

 

I have created a dynamic drop down box which takes all the possible members linked to the particular club for the admin to select from however I am unsure on how to then change the value in the database for the selected user.

 

Here is what I have so far:

 

<?php
if (isset($_POST['submit'])) { 

//Query to change the select user into Admin
$query = "INSERT INTO users (member_type) VALUES ('Admin')";
$result = @mysql_query ($query);
if ($result) {
echo '<h3></h3>';
}
}
?>

//Dynamic drop down box
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="member"><option value="">Select Member</option>
<?php 
$sql = "SELECT * FROM users WHERE club_id = '$id' AND member_type = 'Member'";
  	$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
	$user_id = $row["user_id"];
	$username = $row["username"];
	$club_id == $OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = '';
?>
<option value="<?php echo $user_id ?>" <?php echo $sel ?>><?php echo $username ?></option>
<?php } ?>
</select>

 

Appreciate any help

 

Elliot

Link to comment
Share on other sites

you have to have a field that will determine the type of user eg.. admin, user

 

let say if the account type is 1 its admin then if zero its user

 

now to convert user to admin all you have to do is update that that field into 1 mean admin

Link to comment
Share on other sites

I have a table called users which has a field called member_type.

 

The member_type is either 'Member' or 'Admin'

 

However im unsure on how I update the member_type for member selected in the drop down box?

 

Cheers

Link to comment
Share on other sites

Try something like this.

 

<?php
if (isset($_POST['submit'])) {
$ID = $_POST['member'];
//Query to change the select user into Admin
$query = "INSERT INTO users (member_type) VALUES ('Admin') WHERE club_id = " . $ID;
$result = @mysql_query ($query);
if ($result) {
echo '<h3></h3>';
}
}
?>


//Dynamic drop down box
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="member"><option value="">Select Member</option>

<?php
$sql = "SELECT * FROM users WHERE club_id = '$id' AND member_type = 'Member'";
  	$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
    {
	$user_id = $row["user_id"];
	$username = $row["username"];
        ?>
   <option value="<?php=$user_id?>"<?php echo $username?></option>
        <?php
    }?>


// $club_id == $OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = '';
// This is an if type statment.

Link to comment
Share on other sites

Im nearly there, however something is not quiet right with the drop down box as the initial value displayed should be Select Member - disabled however its not, it displays the last member in the list.

 

The code is working properly however it dosent matter which user you select from the list, it changes the bottom user in the list to Admin.

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="member"><option value="" selected disabled>Select Member</option>
<?php 
$sql = "SELECT * FROM users WHERE club_id = '$id' AND member_type = 'Member'";
  	$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
	$user_id = $row["user_id"];
	$username = $row["username"];
	$club_id == $OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = '';
?>
<option value="<?php echo $user_id ?>" <?php echo $sel ?>><?php echo $username ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td align="center">
<input name="submit" value="Convert Member To Admin" type="submit" />
</form>
<?php
if (isset($_POST['submit'])) {

$update = "UPDATE users SET member_type='Admin' where user_id='$user_id'" or die(mysql_error());
mysql_query($update) or die(mysql_error());
echo '<center><h3>Member converted to Admin</h3></center>';
}
?>

Link to comment
Share on other sites

everything is right!

 

look

$update = "UPDATE users SET member_type='Admin' where user_id='$user_id'" or die(mysql_error());

 

since you use a condition for post data i supposed $user_id<--- is a post data since you use that you will really get the last record in the db because its the last record from your query!

 

change $user_id  to $_POST['member']

Link to comment
Share on other sites

Ok what you do is make the Select member the permenant item

<option value="" SELECTED>Select Member</option>

Then it will always be the option.

 

you could do this also

 

<option value="0" SELECTED>Select Member</option>

 

and

 

if($ID <> 0)

  $result = @mysql_query ($query);

 

You can't have a none exixtent member selected for admin.

 

Desmond.

 

 

 

 

Link to comment
Share on other sites

$club_id == $OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = '';

^^^ i guess that is the prob can you explain what you want with that

 

ternary operator goes like this

 

$teng = ($teng=='cool')?'cool':'not coool';

 

echo  $teng;//cool

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.