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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:31:11+00:00 2026-06-03T09:31:11+00:00

I have these 3 if statements which depending on the value in the variable

  • 0

I have these 3 if statements which depending on the value in the variable will either put it into one column or another. But for some reason it always uses only one of the 3 even if the if statement should be false. I have placed the code below. Thanks for any help.

$link = mysql_connect('localhost', 'root', '');
if (!$link) {
  // error happened
  print(0);
}
mysql_select_db('test');

// sanitize the value
$value = mysql_real_escape_string($_GET['uname']);
$id = mysql_real_escape_string($_GET['id']);

if($value == "Paid" || "Waiting on Payment"){
  $sql = "UPDATE test SET payment='$value' WHERE id='$id'";
}

if($value == "Repaired" || "Waiting on Repairs"){
  $sql = "UPDATE test SET repair='$value' WHERE id='$id'";
}

if($value == "With Student" || "Awaiting Pickup"){   //Always uses this one for somereason unknown to me..
  $sql = "UPDATE test SET returned='$value' WHERE id='$id'";
}

// start the query
// check if the query was executed
if(mysql_query($sql, $link)){
  // everything is Ok, the data was inserted
  print(1);
  echo $sql;    
} else {
  // error happened
  print(0);
}

?>
  • 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-06-03T09:31:13+00:00Added an answer on June 3, 2026 at 9:31 am

    The previous solutions don’t address the problem.

    What you need to use is the if-else block after if.

    if(conditionA is true){
      //do taskA
    }
    else if(conditionB is true){
      //do taskB
    }
    else if(condition is true){
      //do taskC
    }
    else {
      //do taskD
    }
    

    That answers your question.

    But then comes the next problem, which is answered @ https://stackoverflow.com/a/10492151/260034 by “A Bag”. It is because the strings “Waiting on Payment”, “Waiting on Repairs”, etc always get evaluated to TRUE. So even if $value is not equal to “Paid”, the string “Waiting on Payment” evaluates to TRUE.

    The OR operator || returns TRUE if either of the 2 operands evaluates to TRUE.

    So all your if statements evaluate to TRUE and since you have a bunch of if statements and not an if-ifelse block, the block of code in your last if condition seems to be the one which is always executing.

    The revised code would be something like,

    
    if($value == "Paid" || $value == "Waiting on Payment"){
      $sql = "UPDATE test SET payment='$value' WHERE id='$id'";
    }
    else if($value == "Repaired" || $value == "Waiting on Repairs"){
      $sql = "UPDATE test SET repair='$value' WHERE id='$id'";
    }
    else if($value == "With Student" || $value == "Awaiting Pickup"){
      $sql = "UPDATE test SET returned='$value' WHERE id='$id'";
    }
    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these long statements that I will refer to as x,y etc. here.
Let's say you have 10 variables, one of which will be true and the
I have these 2 statements: $pow= mysql_query(select options.label from options where userid='1'); and: $sql=(SELECT
I have these two statements : printf(%u,a+1); and printf(%u,(int *)a+1); Actually I was working
I have a controller factory which depending on the route values builds a controller
I have string inputs, and depending on the value of that input, I'd like
I'm trying to create a custom control - a button - which will have
Below I have a nested if statement which loads a certain CSS file depending
Is there any way to have a Windows batch file directly input SQL statements
If I have variable of type IEnumerable<List<string>> is there a LINQ statement or lambda

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.