This topic is locked

Check for NULL

2/9/2009 12:22:01 PM
PHPRunner General questions
T
taumic author

Hallo,
I use PHPR 5.0 (766) with MySQL.

I want to check whether a DB-Field (RG_POS.RGP_EK) is NULL, but I get only error messages.

Is anybody here in the forum, who can give me the right syntax and preferably a example ?
Thanks a lot !
I need it in the events (Before record added)

A
amuro 2/9/2009

MySQL syntax for querying column of null value like this.
For example, SELECT field_a FROM table WHERE field_b IS NULL
It's wrong like this, SELECT field_a FROM table WHERE field_b = NULL

T
taumic author 2/10/2009

Thank you Amuro,
here is a small code:
[codebox]if(

($values["RGP_EK"] == 0 )

or ($values["RGP_EK"] is Null)

or ($values["RGP_MARGE"] == 0 )

or ($values["RGP_MARGE"] is Null)

)

{

$echo "Achtung: es ist was 0 oder NULL !" ;

}
return true;

[/codebox]
..and that is the effect:
"Parse error: syntax error, unexpected T_STRING in D:\Server\WWWROOT\Alaska\include\rg_pos_events.php on line 111"
where line 111 = " or ($values["RGP_EK"] is Null)"
So what is wrong ?
Thank you!

G
gawde 2/10/2009

Thank you Amuro,

here is a small code:
[codebox]if(

($values["RGP_EK"] == 0 )

or ($values["RGP_EK"] is Null)

or ($values["RGP_MARGE"] == 0 )

or ($values["RGP_MARGE"] is Null)

)

{

$echo "Achtung: es ist was 0 oder NULL !" ;

}
return true;

[/codebox]
..and that is the effect:
"Parse error: syntax error, unexpected T_STRING in D:\Server\WWWROOT\Alaska\include\rg_pos_events.php on line 111"
where line 111 = " or ($values["RGP_EK"] is Null)"
So what is wrong ?
Thank you!


I believe "echo" should be without the "$".

T
taumic author 2/10/2009

Hallo greg_de,
you are right, but there must be a nother mistake (in line 111 = " or ($values["RGP_EK"] is Null)" ),

and I can`t find it .
Have any other user an idea ???
Thanking you in anticipation

A
alang 2/10/2009

Looks to be a bit of confusion between SQL and PHP. The "IS NULL" is applicable in an SQL statement. In PHP try:
if((!$values["RGP_EK"])

or (!$values["RGP_EK"])

or (!$values["RGP_MARGE"])

or (!$values["RGP_MARGE"]))
This should return TRUE if any of the values are NULL or 0 which I think is what you want.

T
taumic author 2/11/2009

Hallo AllanG,
many thanks for your SOLUTION !!
That was the mistake .....