Tim Johnstone
Tim Johnstone

Reputation: 363

IF statement to change a userType to 'admin'

In an sql table there are 3 fields:

I am doing some admin functionality and am having trouble with the syntax whereby i'm wanting to create a so that when it is clicked on, it will run an IF statement to check whether a user's userType is either a jobseeker or an employer and if so, change their userType to admin.

Here is the code so far (I haven't got very far..)

<div id="makeAdmin">
    <?php
    $sQuery = 'SELECT userID, userType FROM user';

       $result = mysql_query($sQuery);

    //IF STATEMENT T CHANGE USER TO ADMIN
       if ($userType == "jobseeker" || "employer") {

         //CHANGE userType to 'admin'
         //Call the function inside a button
        }
 ?>
 </div>

Does anyone know how to change the userType to 'admin'? All help is much appreciated.

Upvotes: 1

Views: 443

Answers (2)

Fahim Parkar
Fahim Parkar

Reputation: 31647

isn't your if condition should be

if (($result->userType == "jobseeker") || ($result->userType == "employer"))

Upvotes: 0

JuSchz
JuSchz

Reputation: 1198

Try somthing like this :

<div id="makeAdmin">
<?php
$sQuery = mysql_query('SELECT userID, userType FROM user');
$result = mysql_fetch_object($sQuery);

//IF STATEMENT T CHANGE USER TO ADMIN
   if ($result->userType == "jobseeker" || $result->userType == "employer") {

     //CHANGE userType to 'admin'
     //Call the function inside a button
    }
?>
</div>

Upvotes: 2

Related Questions