943,693 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 514
  • PHP RSS
Sep 11th, 2009
0

Trouble with is_null()

Expand Post »
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...}
Similar Threads
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Sep 11th, 2009
0

Re: Trouble with is_null()

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:
PHP Syntax (Toggle Plain Text)
  1. if ( $row['log_check'] == 'NULL' ) {
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 11th, 2009
0

Re: Trouble with is_null()

That was what I thought originally, but that isn't working either. :-(
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Sep 11th, 2009
0

Re: Trouble with is_null()

Print the row out using print_r() or use var_dump on $row['log_check'] to see what the value is.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 11th, 2009
0

Re: Trouble with is_null()

Array
(
    [0] => 
    [log_check] => 
)
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Sep 11th, 2009
0

Re: Trouble with is_null()

OK so that last one was from print_r() var_dump has given much better results:

var_dump($row['log_check']);
returns NULL
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Sep 11th, 2009
0

Re: Trouble with is_null()

I think empty() would be the function of choice here.
Last edited by kkeith29; Sep 11th, 2009 at 6:24 pm.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Sep 11th, 2009
0

Re: Trouble with is_null()

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!!
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Sep 11th, 2009
0

Re: Trouble with is_null()

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: How can php recognize user?
Next Thread in PHP Forum Timeline: Find random string between main string?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC