Page 1 of 1
PHP elseif statement and dynamic fields.
Posted: Fri Apr 06, 2007 10:41 pm
by rxroids
I'm very new to PHP and so I've created a dynamic text field and when someone fills it out I want it to "echo" a response and what the person put in the field itself. But if the person left it blank I don't want it to "echo" anything. I've looked everywhere for an answer but I'm not even sure I'm using the right code or if I should even be using "elseif" statements.
Code: Select all
$editor = $_POST['editor'];
if( $editor = $_POST['editor'])
{
echo 'Ed. '.$_POST['editor'];
}
else
{
echo '';
}
Should I use another code?
Re: PHP elseif statement and dynamic fields.
Posted: Sat Apr 07, 2007 12:06 am
by Christopher
Maybe:
Code: Select all
if ((isset($_POST['editor']) && ($_POST['editor'] != ''))
{
echo 'Ed. '.htmlentities($_POST['editor']);
}
Thanx a lot
Posted: Sat Apr 07, 2007 1:01 pm
by rxroids
A while ago I bought a PHP and MySQL web dev book and I used it to define your code. I ran it and it sent back an error so I debugged it and got the results I needed from the first part of your code, then I just plugged in my own thing. I never would have even thought of it if it weren't for that piece of code. Thanks a lot.
Code: Select all
if(isset($_POST['editor'])&&($_POST['editor']!= ''))
I'll be back soon...lol.
Posted: Sat Apr 07, 2007 1:22 pm
by aaronhall
Nobody likes
empty() for some reason
So much nicer to look at
Posted: Sat Apr 07, 2007 1:29 pm
by nickvd
aaronhall wrote:Nobody likes
empty() for some reason
So much nicer to look at
I use empty() all the time.. It's much better than if (isset($) and $ != '') every single time
Posted: Sun Apr 08, 2007 3:23 pm
by RobertGonzalez
Yes it is. Empty actually checks isset() as well, I believe.
PS Arborints code had one too many opening parentheses in it. It wasn't bad code.
Posted: Sun Apr 08, 2007 5:22 pm
by Weirdan
nickvd wrote:
I use empty() all the time.. It's much better than if (isset($) and $ != '') every single time
Except those situations when you actually do want to accept "0" string.