Azarian Posted February 11, 2008 Share Posted February 11, 2008 I have a db to script issue when I try to check a users level. Here is the SQL for the field I am checking. fld_user_level enum('0','1','2','3','4','5') NOT NULL default '1', Here is the php code that is failing on me. It is supposed to to retrieve a users level than if it is a level 2 and higher user it is supposed to do a certain operation. If a level 1 user it does a different operation. Except it runs the script as if all users are level 1. I am fairly sure the issue is because in the DB user_level is enum but if I switch it to int the db errors when I try to do this. Any suggestions on what to do would be appreciated! $sql_validation_check = mysql_query("SELECT fld_user_level='$user_level' FROM tbl_user_access WHERE fld_emailaddress='$email_address'"); if($user_level > 1) { Stuff happens here for lvl 2 and higher users; } else { Stuff happens here for lvl 1 users; } Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/ Share on other sites More sharing options...
teng84 Posted February 11, 2008 Share Posted February 11, 2008 dont know what do you mean by this! SELECT fld_user_level='$user_level' FROM tbl_user_access WHERE fld_emailaddress='$email_address' Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463747 Share on other sites More sharing options...
Azarian Posted February 11, 2008 Author Share Posted February 11, 2008 dont know what do you mean by this! SELECT fld_user_level='$user_level' FROM tbl_user_access WHERE fld_emailaddress='$email_address' I am trying to retrieve the user_level From tbl_user_access Where is based on the users email. Its pretty simple and straight forward. Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463748 Share on other sites More sharing options...
peranha Posted February 11, 2008 Share Posted February 11, 2008 where is the result at like $user_level = mysql_query($sql_validation_check) Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463751 Share on other sites More sharing options...
mmarif4u Posted February 11, 2008 Share Posted February 11, 2008 I did not see this before: SELECT fld_user_level='$user_level' you have to retrieve the value 1st by PHP from table or Database then compare it with your variable. OR compare it in where clause. Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463753 Share on other sites More sharing options...
teng84 Posted February 11, 2008 Share Posted February 11, 2008 maybe you mean.. $sql_validation_check = mysql_query("SELECT * FROM tbl_user_access WHERE fld_emailaddress='$email_address'"); $row =mysql_fetch_array($sql_validation_check); if($row['fld_user_level'] > 1) { Stuff happens here for lvl 2 and higher users; } else { Stuff happens here for lvl 1 users; } Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463754 Share on other sites More sharing options...
Azarian Posted February 11, 2008 Author Share Posted February 11, 2008 LOL good call everyone! I noobed myself! Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463755 Share on other sites More sharing options...
teng84 Posted February 11, 2008 Share Posted February 11, 2008 very straight forward? Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463757 Share on other sites More sharing options...
Azarian Posted February 11, 2008 Author Share Posted February 11, 2008 very straight forward? Yea! I been staring at it to long tonight! Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463760 Share on other sites More sharing options...
Azarian Posted February 11, 2008 Author Share Posted February 11, 2008 Nope I still have the same problem! This is what I updated it too. $sql_validation_check = mysql_query("SELECT fld_user_level='$user_level' FROM tbl_user_access WHERE fld_emailaddress='$email_address'"); $user_level = mysql_query($sql_validation_check); if($user_level > 1) { Stuff happens here for lvl 2 and higher users; } else { Stuff happens here for lvl 1 users; } Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463763 Share on other sites More sharing options...
mmarif4u Posted February 11, 2008 Share Posted February 11, 2008 Please use this code[teng84]: $sql_validation_check = mysql_query("SELECT * FROM tbl_user_access WHERE fld_emailaddress='$email_address'"); $row =mysql_fetch_array($sql_validation_check); if($row['fld_user_level'] > 1) { Stuff happens here for lvl 2 and higher users; } else { Stuff happens here for lvl 1 users; } Your code is completely wrong. Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463766 Share on other sites More sharing options...
Wolphie Posted February 11, 2008 Share Posted February 11, 2008 When using the SELECT statement it should be like this SELECT `field_name` FROM `table_name` WHERE `field_name_data` = '" . $variable . "' You CANNOT use a variable when trying to select a field. Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463767 Share on other sites More sharing options...
Azarian Posted February 11, 2008 Author Share Posted February 11, 2008 Please use this code[teng84]: $sql_validation_check = mysql_query("SELECT * FROM tbl_user_access WHERE fld_emailaddress='$email_address'"); $row =mysql_fetch_array($sql_validation_check); if($row['fld_user_level'] > 1) { Stuff happens here for lvl 2 and higher users; } else { Stuff happens here for lvl 1 users; } Your code is completely wrong. This code will select all users won't it? I just want 1 particular user! Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463895 Share on other sites More sharing options...
Azarian Posted February 11, 2008 Author Share Posted February 11, 2008 When using the SELECT statement it should be like this SELECT `field_name` FROM `table_name` WHERE `field_name_data` = '" . $variable . "' You CANNOT use a variable when trying to select a field. Yea I will give that a try! Quote Link to comment https://forums.phpfreaks.com/topic/90457-problems-with-comparing-a-value-to-a-db-value/#findComment-463896 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.