mardi 28 février 2017

else not executing in php

If I leave all the fields blank, the code blow is not showing the else message.

<form action="index.php" method="POST">
    <textarea name="input_area" rows="6" cols="20"></textarea><br/><br/>
    Search<input type="text" name="find"/><br/><br/>
    Replace<input type="text" name="replace" /><br/><br/>
    <input type="submit" value="Find and replace"/>
</form>

PHP

if(isset($_POST['input_area'])&&($_POST['find'])&&($_POST['replace']))
{
    $text=$_POST['input_area'];
    $find=$_POST['find'];
    $replace=$_POST['replace'];

    if(!empty($text)&&!empty($find)&&!empty($replace))
    {
        $new_str=str_replace($find,$replace,$text);
        echo $new_str;  
    }
    else
    {
        echo 'FILL ALL THE FIELDS';     
    }
}

Aucun commentaire:

Enregistrer un commentaire