zero_ZX Posted March 31, 2009 Share Posted March 31, 2009 Hi all, I'm having some problems with my "if els" statement.. I want my users to upgrade their forum account via my client area, however i only want them to upgrade an account which is member of a specefic group on the forum. So i reached this: A user input his username in a form, which posts: <form action="client_forum_complete.php" method="post"> Forum username : <input type="text" name="name" /> <input type="submit" /> </form> So this is the get one, and i need help with the "[the membergroup of the username]" part, since i dunno what to replace it with no toturials on the net for exactly that thing.. (or i was just too dumb to find it). <?php $con = mysql_connect("localhost","root","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("forumdb", $con); if ([the membergroup of the username] != 3) //here the statement begins { //If member is not a member of membergroup 3 echo "Your account is either a staff account, banned account, or not validated. The process has failed. Please contact the staff."; } else { //If member is a member of the third membergroup: mysql_query("UPDATE ibf_members SET mgroup = '7' WHERE name = '{$_POST['name']}'"); echo "Your account has been upgraded."; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/ Share on other sites More sharing options...
lonewolf217 Posted March 31, 2009 Share Posted March 31, 2009 how is group membership stored in the database ? is it another column in the same table ? is it another table ? Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797900 Share on other sites More sharing options...
zero_ZX Posted March 31, 2009 Author Share Posted March 31, 2009 Wow thanks for the instant reply Yea they are in same table Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797902 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 Since the form submits the user's name, you're going to need to query the table ibf_members for their name. If the query finds results, use their mgroup as the variable to check it's != 3 Follow? Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797903 Share on other sites More sharing options...
wildteen88 Posted March 31, 2009 Share Posted March 31, 2009 You'll have to pull their current membergroup from your database first <?php $con = mysql_connect("localhost","root","***"); if (!$con) die('Could not connect: ' . mysql_error()); mysql_select_db("forumdb", $con); if(isset($_POST['name']) && trim($_POST['name']) != '') { $name = mysql_real_escape_string($_POST['name']); $result = mysql_query("SELECT mgroup FROM ibf_members WHERE name = '$name'"); if(mysql_num_rows($result) == 1) { list($membergroup) = mysql_fetch_row($result); if ($membergroup != 3) //here the statement begins { //If member is not a member of membergroup 3 echo "Your account is either a staff account, banned account, or not validated. The process has failed. Please contact the staff."; } else { //If member is a member of the third membergroup: mysql_query("UPDATE ibf_members SET mgroup = '7' WHERE name = '$name'"); echo "Your account has been upgraded."; } } else { // User not found echo "Sorry, Please verify the username provided is correct. The Username provided was not found"; } } else { echo "Please provide username"; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797906 Share on other sites More sharing options...
zero_ZX Posted March 31, 2009 Author Share Posted March 31, 2009 Ahh got it! Thank you so much didnt know it was called "select" i though it was called "read" that might be the reason i wasnt able to find any toturials Thanks again for this usefull lesson. Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797909 Share on other sites More sharing options...
lostnucleus Posted March 31, 2009 Share Posted March 31, 2009 $query = "select id from from tableName where username = '$_Post['username']' and usergorup = 3 " $result = mysql_query($query,$con); if(mysql_num_rows($result) < 1) { echo ""Your account is either a staff account, banned account, or not validated. The process has failed. Please contact the staff."; } above code will work just put the correct name of tablename and colum names in the query variable... anywayz y are u using curly brackets here ?? '{$_POST['name']}'" Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797911 Share on other sites More sharing options...
zero_ZX Posted March 31, 2009 Author Share Posted March 31, 2009 Els i get error for some reason Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-797923 Share on other sites More sharing options...
zero_ZX Posted March 31, 2009 Author Share Posted March 31, 2009 Hi all, I tried the code used by nucleus to determ wether a user alreaddy made a forum account or not: so this would be my code if(mysql_num_rows($result) < 1); that one gives me error but i don't know why? I'm selecting a new db and tables etc.. check the email (it has same name in both forum and the other db), and then check that the forumacc=0 (i have other parts where i change this to 1 if an account is created). Oh yea and i changed name to email to make sure the client didn't upgrade an account which it wheren't supposed to... mysql_select_db("phpaudit", $con); $query = "select email FROM phpaudit_clients WHERE email = {$_POST['email']} and forumacc = 0"; $result = mysql_query($query,$con); if(mysql_num_rows($result) < 1); /this one gives errors { echo "An error occoured: <br /> Either your email on your forum account didn't match your client account's email <br /> Or maybe you have alreaddy upgraded a forum account? You are only allowed to upgrade one forum account."; die(); } Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-798074 Share on other sites More sharing options...
lostnucleus Posted April 4, 2009 Share Posted April 4, 2009 The best solution of your problem is to first (which i use myself in situations like these) is to use mysql command promt to check mysql quries working correct or not , then only i use them in php ......i wd suggest you either to go by this approach or atleast use $result = mysql_query($query,$con) or die(mysql_error()); in every mysql command you use , so you can tell us abt the error you are getting......... Quote Link to comment https://forums.phpfreaks.com/topic/151941-if-els-help/#findComment-800988 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.