jimjim Posted April 14, 2011 Share Posted April 14, 2011 hi, this is my first post, i hope someone here can give me a hand with this. i have created a new field in the member_profile table in my database. lets say i named it newfield. i would like a yes to be placed in this newfield at the same time i give moderator privlages to a member. i can manually enter a yes in newfield now with phpmyadmin. i believe this code applies the moderator settings, any ideas on a way to have this post yes in my new field as well. //make Moderator ////////////////////// if (isset($_POST['moderator']) && isset($_POST['list'])) { foreach ($_POST['list'] as $user_id) { managemember($user_id,'moderator'); } //notifications $show_notification = 1; $message = notifications(1); } any help greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/ Share on other sites More sharing options...
zander1983 Posted April 14, 2011 Share Posted April 14, 2011 Apply the sql to your member table Update set newfield = "yes" where UserID = $user_id You should just use a bool rather than a varchar for your newfield. So if you field is called "Moderator", insert 1 to allow moderator staus, and 0 for all else Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1201658 Share on other sites More sharing options...
jimjim Posted April 14, 2011 Author Share Posted April 14, 2011 ok set it up as bool and it now takes a value of 1 in newfield but i still have to add it manualy. i still cant get the script to add a 1 at the same time that i set a member to moderator. it adds a 1 to the moderator field but not to the newfield. any ideas. Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1201773 Share on other sites More sharing options...
spiderwell Posted April 15, 2011 Share Posted April 15, 2011 have you echoed out your sql statement to check exactly what it is doing? Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1201830 Share on other sites More sharing options...
mike12255 Posted April 15, 2011 Share Posted April 15, 2011 managemember() <-- this will be a function made from whoever made that script. You will need to find that function and edit its sql statement that changes person to a moderater. Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1201836 Share on other sites More sharing options...
jimjim Posted April 15, 2011 Author Share Posted April 15, 2011 hi, i hope this makes sense i don't have much experience with this stuff. i have this adding a one to newfield in my database what would i need to do to make this check if newfield = 1 change newfield back to 0 $sql = "SELECT * FROM member_profile SET newfield = '1' WHERE userid = $user_id"; Many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1202148 Share on other sites More sharing options...
kansasakki Posted April 15, 2011 Share Posted April 15, 2011 I am no pro at all but I see a SELECT statement instead of an UPDATE ? I am brand new so this might be way off as well. Kansas Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1202167 Share on other sites More sharing options...
jimjim Posted April 18, 2011 Author Share Posted April 18, 2011 hi kansas thanks, i pasted the wrong code this is the code that sets newfield to 1. $sql = "UPDATE member_profile SET newfield = '1' WHERE user_id = $user_id"; what i would like to do is make this code check to see if newfield = 1 and if it does change newfield back to 0 Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1203131 Share on other sites More sharing options...
kansasakki Posted April 18, 2011 Share Posted April 18, 2011 I think the steps are just about there. Me being new as well, I still get lost in what I want to do and what I am telling the code to do. $sql = "SELECT * FROM member_profile SET newfield = '1' WHERE userid = $user_id"; $qry = mysql_query($sql); $res = mysql_assoc($qry) if($res['newfield'] == 1){ $sql = "UPDATE member_profile SET newfield = '0' WHERE user_id = $user_id"; $upresult = mysql_query($sql); if(mysql_affected_rows()== 1){ //update successfull }else{ //update failed } } I think this will get you closer, I did not test it but I tried to make sure the syntax was correct. I still make a lot of errors when writing code blocks and debug them constantly Kansas Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1203141 Share on other sites More sharing options...
jimjim Posted April 21, 2011 Author Share Posted April 21, 2011 hi Kansas, i have tried the code every way that i can think of but it will not replace the 1 with a 0 i get a blank screen with this in the code $res = mysql_assoc($qry); when i remove it places a 1 in newfield but won't replace it with 0 any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1204659 Share on other sites More sharing options...
kansasakki Posted April 21, 2011 Share Posted April 21, 2011 hi Kansas, i have tried the code every way that i can think of but it will not replace the 1 with a 0 i get a blank screen with this in the code $res = mysql_assoc($qry); when i remove it places a 1 in newfield but won't replace it with 0 any ideas? In the code I posted, I left out the semi colon in the code have you tried it adding a semi colon to terminate the line as you have posted it ? $res = mysql_assoc($qry); ?? That syntax error could cause a blank screen. Another step in the debugging process I would take would be to do an $sql = "SELECT * FROM member_profile SET newfield = '1' WHERE userid = $user_id"; $qry = mysql_query($sql); $res = mysql_assoc($qry); echo '<pre>'; print_r ($res); echo '</pre>'; if($res['newfield'] == 1){ $sql = "UPDATE member_profile SET newfield = '0' WHERE user_id = $user_id"; $upresult = mysql_query($sql); if(mysql_affected_rows()== 1){ //update successfull }else{ //update failed } } the print_r will allow you to see the array values in $res. Kansas Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1204663 Share on other sites More sharing options...
jimjim Posted April 22, 2011 Author Share Posted April 22, 2011 Kansas, Ok that got me fixed up. Thank you your help is really appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/233737-add-yes-to-new-field-in-database/#findComment-1204826 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.