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 6626713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:55:36+00:00 2026-05-25T21:55:36+00:00

I am having trouble with a simple peice of php code. I am working

  • 0

I am having trouble with a simple peice of php code.

I am working with 2 product pricing tiers. These are based on whether a user has logged in, or not.

If a user is not logged in, and the first price is empty; then the price is price1. If not, it is price1.

This works perfectly fine.

If a user is logged in, and the first price is empty; then the price is price1. If not, it is price2.

This is the way it should work, but what actually happens is this:

If a user is logged in, and the first price is empty; then the price is 0. If not, it is price2.

Why is my code producing this effect?

if (!userIsLoggedIn())
{
    if (empty($prPrice2))
    {
        $prPrice = $prPrice1;
    }
    else
    {
        $prPrice = $prPrice1;
    }
} else if (userIsLoggedIn())
{
    if (empty($prPrice2))
    {
        $prPrice = $prPrice1;
    }
    else
    {
        $prPrice = $prPrice2;
    }
} else 
{
    $prPrice = $prPrice1;
}

If anyone has any suggestions that could help me to resolve this issue, it would be greatly appreciated.

Thank you!

@Pekka, it is fairly complicated. I simply would like this to happen:

product 1 -> price 1 = 1.00
product 1 -> price 2 = 0.00
product 2 -> price 1 = 1.00
product 2 -> price 2 = 0.80

If a user is logged in but the price2 field is empty, then the price variable will be price1. if not, then it will be price 2.

On the other hand, if a user is not logged in but the price2 field is empty, then the price variable will be price1. if not, then it will be price 1.

  • 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-25T21:55:37+00:00Added an answer on May 25, 2026 at 9:55 pm

    You code is overly complicated and contains some odd constructions. This is an equivalent but simplified version, but check the comment I added on the first else….

    if (!userIsLoggedIn())
    {
        if (empty($prPrice2))
        {
            $prPrice = $prPrice1;
        }
        else
        {
            $prPrice = $prPrice1;  // this is highly suspicious...
        }
    } else {    // user is logged or not, no need to recheck that boolean var
        if (empty($prPrice2))
        {
            $prPrice = $prPrice1;
        }
        else
        {
            $prPrice = $prPrice2;
        }
    } 
    

    a slightly fancier way of expressing the same condition with the ternary statement (example is equivalent to else block of the outer if:

    $prPrice = (empty($prPrice2)) ? $prPrice1 : $prPrice2;
    

    EDIT

    Assuming that there is a way to differentiate between accountholders that haven’t logged in and users without accounts, your need to handle that in an outer condition, like this:

    if ($UserHasAnAccount) {  
    // but i don't understand (yet) how you'd know that at this point
        if (userIsLoggedIn()) {  // the price logic described before
            ....
        } else {
            ....
        }
    } else {  // unknown user, price1
        $prPrice = $prPrice1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble working out how to get a simple fade in fade
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing
I am having some trouble getting this simple code to work: #pragma once #include
I'm having trouble doing simple functions on a data frame and am unsure whether
I am having trouble with the most simple piece of code. For some reason,
Hi I'm having trouble compiling a simple piece of code. I am creating a
I'm learning Python, and I'm having trouble with this simple piece of code: a
I'm having trouble with a simple radio set of two radio buttons (I don't
I'm new to linq and having trouble writing two simple queries. For some reason,
I'm having trouble sending out a simple HTTP request using Actionscript 3's Socket() object.

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.