Null value

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Null value

Post by mariolopes »

How can i detect if a field is null? I try the is_nukk function but it seems doesn't work. Please review the following code:
<html>
<?php
if(!isset($_POST['Idade'])){
print "Valor zero";
}
if(is_null($_POST['Idade'])){
print "Tá branco";
}

?>
<form action="isset.php" method="post">
<p>Idade:<input type="text" name="Idade" value="" /></p>
<p>Valor:<input type="text" name="Valor" value="" /></p>
<p><input type="submit" value="Enviar!" /></p>
</form>
</html>
mariolopes
Forum Contributor
Posts: 102
Joined: Sun May 22, 2005 7:08 am

Re: Null value

Post by mariolopes »

Solved
if(isset($_POST['Idade']) || $_POST['Idade']&&""){
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Null value

Post by AbraCadaver »

You're not going to get a null value from a form, maybe an empty value:

Code: Select all

if(isset($_POST['Idade']) && !empty($_POST['Idade'])){
    //
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply