I just can not deal with isset.

<html> <head></head> <body> <table border="1" align="center"> <tbody> <form name='action' action='admin.php' method='POST'> <tr><td>Имя :</td> <td> <input type='text' name='author'><br/></td></tr> <tr><td>Заголовок :</td> <td> <input type='text' name='title'><br/></td></tr> <tr><td>Текст<br/> новости :</td> <td><textarea cols="30" name='news'>Введите текст</textarea></td> </tr> <tr> <td></td> <td><input name="submit" type='submit' value='Отправить'></td></tr> </form> </tbody> </table> <?php require_once 'config.php'; if (isset($_POST['submit'])) { $name = $_POST['author']; $title = $_POST['title']; $news = $_POST['news']; if (!isset($name)) { echo "Вы не ввели имя"; } if (!isset($title)) { echo "Вы не ввели заголовок"; } if (isset($news)) { echo "Вы не ввели текст новости"; } else { echo "$name $title $news"; } } ?> </body> </html> 

    3 answers 3

    1) isset here out of place, if you declare a variable - then it definitely is!
    2) else does not understand (you) what

    Alternatively, you can:

     if (isset($_POST['submit'])) { $name = $_POST['author']; $title = $_POST['title']; $news = $_POST['news']; $ok = true; if ( empty($name) ){ $ok = false; echo "Вы не ввели имя<br>"; } if ( empty($title) ){ $ok = false; echo "Вы не ввели заголовок<br>"; } if ( empty($news) ){ $ok = false; echo "Вы не ввели текст новости<br>"; } if ( $ok ){ echo $name.' '.$title.' '.$news; } } 
    • And if you don’t declare a variable, how can you do it competently? - ilussion86
    • Explain what you want to receive - and then it will be possible to suggest something. <br> PS What is not satisfied with the code in the answer? - timka_s
    • Well, organize a check for empty fields by means of isset or empty - ilussion86
    • Be kind, tell me - ilussion86
    • Tell me, why was the variable $ ok created? - ilussion86

    The condition will be fulfilled only when isset ($ news) is entered news (it is not clear why everything is checked for absence, and $ news for the presence in $ _POST)

    I think something like that

     if(!isset($_POST[name])) { echo "Вы не ввели имя"; } elseif(!isset($_POST[title])) { echo "Вы не ввели заголовок"; } elseif(!isset($_POST[news])) { echo "Вы не ввели текст новости"; } else { echo "$name $title $news"; } 
       <?php require_once 'config.php'; $err= array(); if (isset($_POST['submit'])) { $name = $_POST['author']; $title = $_POST['title']; $news = $_POST['news']; if (strlen($name)<4 && strlen($name)>32) { $err[]="Вы не ввели имя"; } if (strlen($title)<10 && strlen($title)>64) { $err[]= "Вы не ввели заголовок"; } if (strlen($news)<3 && strlen($news)>1024) { $err[]= "Вы не ввели текст новости"; } if(!isset($err)) { echo $name."-".$title."-".$news; } if (is_array($err)) { foreach ($err as $key=>$value) { echo "$value\n"; } } } ?>