Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6757047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:35:59+00:00 2026-05-26T13:35:59+00:00

I am working with a simple function that returns true when checking if a

  • 0

I am working with a simple function that returns true when checking if a user has an appropriate account type.

function userHasType($type)
{
    include $_SERVER['DOCUMENT_ROOT'] . '/pathTo/db.connection.php';

    $accNum = mysqli_real_escape_string($link, $_SESSION['accountNum']);
    $type = mysqli_real_escape_string($link, $type);

    $sql = "SELECT COUNT(*) FROM users
            INNER JOIN user_types ON users.id = userId
            INNER JOIN types ON typeId = types.id
            WHERE users.id = '$accNum' AND types.id='$type'";
    $result = mysqli_query($link, $sql);
    if (!$result)
    {
        $error = 'Error searching for user types.';
        include 'error.html.php';
        exit();
    }
    $row = mysqli_fetch_array($result);

    if ($row[0] > 0)
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

The function is named userHasType, i currently use this function like this:

$userHasType = userHasType('thisAccount');
.......
if ($userHasType AND whatever) {

I would like to use a statement where basically, if the user does not have a specific type, then this will happen, else something else will happen.

As in:

if (!$userHasType AND whatever) {

or im guessing this would actually work:

$userNotHasType = !userHasType('thisAccount');
.......
if ($userNotHasType AND whatever) {

Which ever way though, what is the right way to go about this… Because I have tried both and for some reason it is not reacting the way i would expect it to. It would be due to something else, but my conclusion is that both these ways must not work.

So some clarity on the matter would be much appreciated.

EDIT:

Thank You!!

if (!$userHasType) {
    $prPrice = ($prPrice2 != 0 && $userIsLoggedIn ) ? $prPrice2 : $prPrice1;
    } else {
    $prPrice = ($prPrice2 != 0 && $userIsLoggedIn ) ? $prPrice2Incl2PIncl : $prPrice1Incl2PIncl;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:36:00+00:00Added an answer on May 26, 2026 at 1:36 pm

    Yes you CAN use the ! operator in front of a function call and you will get the boolean negative of the function call’s return value, and you can do the same to a variable.

    Looking at your function code, it seems to me that type.id might be an integer, rather than a string-type value such as a varchar or text. What does the database show as the type for the column id in the types table?

    As mentioned by Polynomial, I suggest you avoid using AND. && is usually a better choice when you are dealing with normal precedence situations.

    About the use of variables; I think it is good practice to minimize the use of extra variables when reasonable. Of course IMHO this decision is subject to the amount of use the variable has. I suggest sticking with:

    if (!$userHasType && whatever) {
    

    or if you do not use $userHasType anywhere else then just go ahead and use the function call in-line:

    if (!userHasType('thisAccount') && whatever) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am working on a simple web app which has a user model and
I have a simple accordion type mechanism that I've been working on. I am
I have a simple code fragment in JS working with prototype inheritance. function object(o)
I am working on a simple notification service that will be used to deliver
I've been working on a simple JQuery dialog form that loads in via AJAX.
I'm writing a simple AJAX call that returns a full HTML page and then
I'm trying to get auto-complete working with a simple application that I'm building. Here
I'm working with Mootools to develop a simple ajax-y page that does some manipulation
I'm looking for good/working/simple to use PHP code for parsing raw email into parts.
Working on a simple C program I'm stuck with an if test: int line_number

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.