Q: OR Operator not working strictly in mysql php I want a strict condition with update, but it is not working here. I mean if level1 user log in and update a from and submit by this fields belongs to level2 get empty.
My from user level from and entries them only. There are hidden fields also updating with null values. There is way to update only user level fields without effected hidden fields.
if(!empty($_REQUEST['update'])){
    $sql = "SELECT * FROM `tabl1` WHERE `ID` = ".$_REQUEST['update'];
    $query = mysql_query( $sql );
    $res = mysql_fetch_array($query);

    $IndexNo= $_POST['IndexNo'];
    $ZoneID = $_POST['ZoneID'];
    $NameofCoordinator= $_POST['NameofCoordinator'];
    $GridNumber= $_POST['GridNumber'];
    $MobileNumber= $_POST['MobileNumber'];
    $StatusID= $_POST['StatusID'];

    $sql="UPDATE `tabl1` SET `IndexNo` = '$IndexNo',`ZoneID` = '$ZoneID'"; 
    $sql .= if($userName =='admin' || 'level1'){ ",`NameofCoordinator` = '$NameofCoordinator'"; }
    $sql .= if($userName =='admin' || 'level2'){ ", `GridNumber` = '$GridNumber'"; }
    $sql .= if($userName =='admin' || 'level3'){ ",`MobileNumber` = '$MobileNumber'"; }
    $sql .= ",`Keyword` = '$Keyword', `StatusID` = '$StatusID' WHERE `ID` = ".$_REQUEST['update'];
}


A: See http://www.php.net/manual/en/language.operators.logical.php :
$a || $b    Or  TRUE if either $a or $b is TRUE.

So, $userName =='admin' || 'level3' evaluates to ($userName =='admin') || ('level3'), and since 'level3' is not falsy, this will always evaluate to true.
What you probably want is 
$userName == 'admin' || $userName == 'level3'

