Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Check for NULL

Tags:

php

null

mysql

Here is the below Code:

$query = mysql_query("SELECT * FROM tablex");  if ($result = mysql_fetch_array($query)){      if ($result['column'] == NULL) { print "<input type='checkbox' />"; }     else { print "<input type='checkbox' checked />"; } } 

If the values are NOT NULL i still get the uncheked box. Am i doing something wrong from above, shoudnt $result['column'] == NULL work?

Any Ideas?

like image 205
Angel.King.47 Avatar asked Oct 16 '09 05:10

Angel.King.47


People also ask

Is NULL true or false PHP?

NULL essentially means a variable has no value assigned to it; false is a valid Boolean value, 0 is a valid integer value, and PHP has some fairly ugly conversions between 0 , "0" , "" , and false . Show activity on this post. Null is nothing, False is a bit, and 0 is (probably) 32 bits.

How do you know if a variable is NULL?

To check for null variables, you can use a strict equality operator ( === ) to compare the variable with null . This is demonstrated below, where the boolean expression evaluates to true for only for null and evaluates to false for other falsy values.

Is NULL in PHP mysql?

A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. Note: A NULL value is different from a zero value or a field that contains spaces.

How check object is empty or not in PHP?

Therefore you can use count() (if the object is Countable). Or by using get_object_vars() , e.g.


1 Answers

Use is_null or === operator.

is_null($result['column'])  $result['column'] === NULL 
like image 185
The Chairman Avatar answered Sep 21 '22 01:09

The Chairman