Jump to content

"if - els" help


zero_ZX

Recommended Posts

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);
?>

Link to comment
Share on other sites

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);
?>

 

Link to comment
Share on other sites

 

$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']}'"

 

 

 

 

Link to comment
Share on other sites

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();

}

Link to comment
Share on other sites

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.........

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.