Ruko Posted September 10, 2010 Share Posted September 10, 2010 Hello, is there something like this? If mysql record is admin, then a block of code How do I do something like that Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/ Share on other sites More sharing options...
Pikachu2000 Posted September 10, 2010 Share Posted September 10, 2010 If you could just go ahead and clarify that, that would be great, ok? Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109803 Share on other sites More sharing options...
Ruko Posted September 11, 2010 Author Share Posted September 11, 2010 If an mysql value from a table is in a certain text (for example, in the users table, at the permissions column , it says "admin"), then run a block of code Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109809 Share on other sites More sharing options...
mikosiko Posted September 11, 2010 Share Posted September 11, 2010 If an mysql value from a table is in a certain text (for example, in the users table, at the permissions column , it says "admin"), then run a block of code what code have you wrote already?.... Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109814 Share on other sites More sharing options...
Ruko Posted September 11, 2010 Author Share Posted September 11, 2010 I didn't write any code, I can't seem to write it, how do I do this? Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109815 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 pen and pencil for starters : ) But I assume you are trying to setup some sort of user level system where for instance unregistered have no level registered have level 1 and admins level 2. Ones you have that you could make if-statements in your script that checks for a certain userlevel and if it does output stuff. Atleast that what i think you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109835 Share on other sites More sharing options...
Ruko Posted September 11, 2010 Author Share Posted September 11, 2010 $admin = mysql_query("SELECT level FROM users WHERE admin = '¥'") or die(mysql_error()); $array = mysql_fetch_assoc($admin); if ($array['admin'] != '$nonadmins']) { } Hows that code? Similar to deviantart usernames, for example, im the main admin, my username should be: ¥Ruko Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109849 Share on other sites More sharing options...
Ruko Posted September 11, 2010 Author Share Posted September 11, 2010 Bump, anyone want to correct my code? Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109873 Share on other sites More sharing options...
jcbones Posted September 11, 2010 Share Posted September 11, 2010 if ($array['level'] == 'admin']) { //do this; } else { //do that; } Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109902 Share on other sites More sharing options...
Ruko Posted September 11, 2010 Author Share Posted September 11, 2010 Parse error: syntax error, unexpected ']' in /home/minivid/public_html/myart/index.php on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109954 Share on other sites More sharing options...
Ruko Posted September 11, 2010 Author Share Posted September 11, 2010 bump Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109986 Share on other sites More sharing options...
BizLab Posted September 11, 2010 Share Posted September 11, 2010 Hey Ruko, just a thought.. you will want to use numerics to represent different user levels. regular user = 1 admin = 2 king_kong = 3 as far as the error goes, there is an extra "]" bracket in that code if ($array['level'] == 'admin') { //do this; } else { //do that; } Other than that, his code will work just fine. I would prefer to use the $_POST[''] array to deal with the incoming data from the Db though as follows: if ($_POST['level'] == 2) { // you're the admin, go HERE and allow THIS } else { // regular users GO here (use a header re-direct) } Quote Link to comment https://forums.phpfreaks.com/topic/213097-if-mysql-record-is-admin-then-run-a-code/#findComment-1109990 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.