1

I have been looking for an explanation for this, but couldn't find one.

I'm using a Mysql database. In my table I have a column called unitPrice. It's type: decimal(10,2) - unsigned

Now as for my php page:

    $price = mysql_result($rows, $tel, "unitPrice");
    if(is_null($price ) || $price = ""){
           echo " niet ingevuld ";
    }else{
           echo $price ;                                                                             
    }

The if-tag is completed perfectly. Which lets me believe the value is correctly stored into the variable when it comes to NULL and empty values. Now as for the else-tag, it goes wrong. Normally it should collect the value and store it into $price. Like it did with every single other value I collected previously (but stored in the database with other types) But when I went to check my website page, there was no value!

When I placed:

$price = mysql_result($rows, $tel, "unitPrice");
    if(is_null($price) || $price = ""){
           echo " niet ingevuld ";
    }else{
           echo mysql_result($rows, $tel, "unitPrice") ;                                                                             
    }

It showed the result correctly.

It wouldn't be a big problem if it wasn't for the fact that I need the variable somewhere else again and don't wish to keep writing the mysql_result phrase over and over again...

Could anyone please explain why it won't work properly with a variable? And perhaps give me a solution as to how to make it work with a variable?

My apologies if this has been answered before. I've looked around for a while, but couldn't find any answers.

2
  • 1
    At the risk of being unhelpful, you should be using PDO for new code. mysql_ functions are deprecated and not supported Commented May 2, 2013 at 8:59
  • or use MySQLi functions Commented May 2, 2013 at 9:00

2 Answers 2

2

Looking at the code.

if(is_null($EHprijs) || $EHprijs = ""){

Will always evaluate to true. You are assigning "" to $EHprijs instead of doing a comparison

Sign up to request clarification or add additional context in comments.

2 Comments

OMG! >.< How stupid. Thanks for picking that error up! That solved it! Will accept this as the answer when the site allows it
This happens to everyone every once in a while :)
1

This happens because the value is stored in a different variable then the one you are checking. Change $price to $EHprijs

$EHprijs = mysql_result($rows, $tel, "EHprijs");

1 Comment

Oops! Actually it's EHprijs everywhere, but wanted to use $price to make it English. It has nothing to do with this. I'm going to edit my question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.