Checking if variable is null

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
NotOnUrNelly
Forum Commoner
Posts: 61
Joined: Wed Mar 24, 2004 4:45 pm

Checking if variable is null

Post by NotOnUrNelly »

Hi Can anyone help me with the following code,

I have a form that has a mainly radio buttons but also a text box. When the form is submitted if the textbox is blank or empty I want the title text to turn red. If a value is held in the textbox it can remain blue. The variable connected to the text box is named $hours

here is the code I hae tried but wont work can anyone help, I think the error is to do with the isnull($hours and recognising is the variable holds a value

Thanks in advance

<?php if isnull($hours) && isset($submit) {
$not_complete = 1;
echo "RED";
echo "<td bgcolor='#CCD7FF'><font color='#FF0000' size='2' face='Arial, Helvetica, sans-serif'>";
echo "Your number of usual working hours per week over a period of at least 4 weeks, including both paid and unpaid overtime. ";
echo "</font></td>"; }
else
{
$not_complete = 0;
echo "Black";
echo "<td bgcolor='#CCD7FF'><font color='#000000' size='2' face='Arial, Helvetica, sans-serif'>";
echo "Your number of usual working hours per week over a period of at least 4 weeks, including both paid and unpaid overtime. ";
echo "</font></td>";
}
?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

the textbox value won't be NULL but will be blank as in if($hours == "") try that .
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

check using empty()

If it's null, 0, "", or any other non-value - it will return true

If it contains a value will return false.
Post Reply