Ell20 Posted November 1, 2007 Share Posted November 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/ Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383061 Share on other sites More sharing options...
Ell20 Posted November 1, 2007 Author Share Posted November 1, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383063 Share on other sites More sharing options...
otuatail Posted November 1, 2007 Share Posted November 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383069 Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 use update? and be sure that admin can only have this privilege Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383071 Share on other sites More sharing options...
Ell20 Posted November 1, 2007 Author Share Posted November 1, 2007 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>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383074 Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 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'] Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383079 Share on other sites More sharing options...
Ell20 Posted November 1, 2007 Author Share Posted November 1, 2007 It actually changed the username to Admin that you selected now, cheers! I still think its weird that when you first go to the page it says the bottom user in the list rather than "Select Member"? Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383081 Share on other sites More sharing options...
otuatail Posted November 1, 2007 Share Posted November 1, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383083 Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 $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 Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383086 Share on other sites More sharing options...
Ell20 Posted November 1, 2007 Author Share Posted November 1, 2007 Cheers guys, I just removed "$club_id == $OTHER_CLUB_ID ? $sel = 'SELECTED' : $sel = '';" as I was using a drop down box from a previous page and noticed I didnt need that for this one. Thanks for your help Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383088 Share on other sites More sharing options...
teng84 Posted November 1, 2007 Share Posted November 1, 2007 maybe but you also minimize the functionality of your drp menu (determine selected option) Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383095 Share on other sites More sharing options...
Ell20 Posted November 1, 2007 Author Share Posted November 1, 2007 It dosent seem to have had any effect and its working fine? Quote Link to comment https://forums.phpfreaks.com/topic/75700-solved-converting-member_type-member-to-admin/#findComment-383098 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.