无论结果如何,IF语句仅显示1个变量

I have a site where users can join groups and post topics related to that group, I am having an issue where regardless of the user result, it just shows "member" even on a test account that has no records in the database, can someone please explain what I am doing wrong, thank you.

<?php
$id = $_GET['gid'];
$user = $_SESSION['user_id'];

$iropen = "SELECT * FROM `group_users` WHERE user_id='$user' AND group_id='$id'"; 
$resultg = mysql_query($iropen);
$rows = mysql_fetch_array($resultg);

if ($rows['accepted'] = 1) {
    echo 'member';
} else {
    echo 'pending';
}
if ($resultg < 1) {
    echo 'join';
}
?>
if ($rows['accepted'] = 1) {

You need two == here.

if ($rows['accepted'] == 1) {

PHP's operator reference, if you need it: http://www.php.net/manual/en/language.operators.php

What @vinodadhikary is saying is that you have single equal-sign instead of the double-equal-sign in your first IF clause. It should be: if ($rows['accepted'] == 1)...

Try this

<?php
$id = $_GET['gid'];
$user = $_SESSION['user_id'];

$iropen = "SELECT * FROM `group_users` WHERE user_id='".$user."' AND group_id='".$id."'"; 
if($resultg = mysql_query($iropen)){
     $rows = mysql_fetch_array($resultg)
}

if (mysql_num_rows($resultg) < 1) {
    echo 'join';
}else if ($rows['accepted'] == 1) {
    echo 'member';
} else {
    echo 'pending';
}

?>
<?php
    $id = $_GET['gid'];
    $user = $_SESSION['user_id'];

    $iropen = "SELECT * FROM `group_users` WHERE user_id='$user' AND group_id='$id'"; 
    $resultg = mysql_query($iropen);
    $rows = mysql_fetch_array($resultg);
    $num_results = mysql_num_rows($resultg);


    if ($num_results < 1) {
        echo "join";
    } else if ($rows['accepted'] == 1) {
        echo "member";
    } else {
        echo "pending";
    }
?>