Jump to content


Photo

Check to see if value is NULL


  • Please log in to reply
6 replies to this topic

#1 Allen4172

Allen4172
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 19 May 2006 - 02:27 AM

I've tried a couple of things and can't seem to get it to work properly.

I'm attempting to check if a value is NULL. I've tried things like:


if($variable$ == NULL) {
   $php_var = 0;}

The variable isn't from PHP, its from a CMS system, that uses its variables as $something$. With this system, if nothing is typed in, its just blank spaces and the php would see:

if(     == NULL){
   $php_var = 0;}


I'm trying to make it to where, if nothing was entered in, and the script sees the blank, then it would auto put it as 0. Any help or ideas would be appreciated. :)

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 19 May 2006 - 02:00 PM

im not sure i follow, but in a lack of responce - her is a suggestion on setting variables if they don't exist or is false (0):
if(!$var)
{
$var = "whatever";
}


#3 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 19 May 2006 - 05:58 PM

Thanks for the reply.

In that scenerio when that field is false ($example$) the php sees:

if(!)
{
$var = "whatever";
}

It then gives an error of Parse error: parse error, unexpected ')'



#4 dsk3801

dsk3801
  • New Members
  • Pip
  • Newbie
  • 9 posts
  • LocationDallas, TX USA

Posted 20 May 2006 - 03:24 AM

$var = '$variable$';
if (strlen($var) == 0)
{
    $var = 0;
}

Instant Access - PHP5 / MySQL5 Web Hosting Starting At $2.99 / Month - [a href="http://www.reflex-hosting.com" target="_blank"]http://www.reflex-hosting.com[/a]

#5 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 20 May 2006 - 10:37 AM

[a href=\"http://www.php.net/manual/en/function.is-null.php\" target=\"_blank\"]http://www.php.net/manual/en/function.is-null.php[/a]
....

Orio.
Think you're smarty?

(Gone until 20 to November)

#6 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 20 May 2006 - 06:39 PM

[!--quoteo(post=375438:date=May 19 2006, 11:24 PM:name=Dave K.)--][div class=\'quotetop\']QUOTE(Dave K. @ May 19 2006, 11:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
$var = '$variable$';
if (strlen($var) == 0)
{
    $var = 0;
}
[/quote]

Thanks Dave, that is exactly what I needed and it now works :) I tried something similar earlier, but I didn't put the single quotes around $variable$ from above.


#7 Houdini

Houdini
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 20 May 2006 - 08:17 PM

There is always empty() as per [a href=\"http://us3.php.net/empty\" target=\"_blank\"]empty()[/a] in the PHP Manual.
We the unwilling, led by the unknowing,
have done so much, for so long, with so little,
that we are now quqlified to do anything, with nothing!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users