ok I'm trying to do something I thought was simple but it won't work. I just have a simple control structure and if the variable is blank I want one thing to happen if its not I want another to happen. Heres an example of my code.
if($var == "")
{
echo "Your name is $var";
}
else
{
echo "You did not enter a name."
}
Any ideas what the problem is?
Very Basic Question
Moderator: General Moderators
Code: Select all
<?php if($var == "")
{
echo "Your name is $var";
}
else
{
echo "You did not enter a name.";
}
?>Code: Select all
<?
if(!$var)
{
echo "You did not enter a name.";
} else {
echo "Your name is $var";
}
?>Code: Select all
<?php
if($var != "")
{
echo "Your name is $var";
}
else
{
echo "You did not enter a name."
}
?>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
To check if a variable is empty (that is is either equal to an empty string or 0) you can use the empty() function:
Mac
Code: Select all
if(!empty($var)) {
echo 'Your name is '.$var;
} else {
echo 'You did not enter a name.';
}