Trouble with is_null()

Reply

Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Trouble with is_null()

 
0
  #1
Sep 11th, 2009
I have been trying to use the function is_null to see if a database value is NULL. When I run this I am looking at the database and the value is definitely NULL, but it is not re-directing to the error.php page.
What have I done wrong??
Thanks Guys :-)

	$sql = "
	SELECT log_check 
	FROM users 
	WHERE user_ID= '$user_ID'":
        $perform = mysql_query($sql);
	if(mysql_num_rows($perform)==1)//if the details are found
		{
		$row = mysql_fetch_array($perform);
		if(is_null($row['log_check']))
			{
			header("Location: ../error.php?error=14");
			exit();
			}
		else
			{ etc...}
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Trouble with is_null()

 
0
  #2
Sep 11th, 2009
I doubt that a null value in the database is the same a null in php. Most likely its returning as a string which can be checked like this:
  1. if ( $row['log_check'] == 'NULL' ) {
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: Trouble with is_null()

 
0
  #3
Sep 11th, 2009
That was what I thought originally, but that isn't working either. :-(
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Trouble with is_null()

 
0
  #4
Sep 11th, 2009
Print the row out using print_r() or use var_dump on $row['log_check'] to see what the value is.
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: Trouble with is_null()

 
0
  #5
Sep 11th, 2009
Array
(
    [0] => 
    [log_check] => 
)
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: Trouble with is_null()

 
0
  #6
Sep 11th, 2009
OK so that last one was from print_r() var_dump has given much better results:

var_dump($row['log_check']);
returns NULL
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Trouble with is_null()

 
0
  #7
Sep 11th, 2009
I think empty() would be the function of choice here.
Last edited by kkeith29; Sep 11th, 2009 at 6:24 pm.
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: Trouble with is_null()

 
0
  #8
Sep 11th, 2009
I have tried it on a new blank page, and it is working, but I cannot get it to work on the original page I was writing....I have even copied and pasted the text from the working one to the original one, but it still won't work on the original. I am very confused!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Trouble with is_null()

 
0
  #9
Sep 11th, 2009
I have never had a problem like that before, so can't really help there.

Usually when things like that happen I recode everything in which usually fixes the problem. Its always some simple thing I didn't think about earlier.
Google is your friend.

Use [code] tags.

If you have found a solution to your problem, please mark the thread as SOLVED.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC