There are two files: form.html and cookie_set.php
form.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <form name="entry" action="cookie_set.php" method="POST"> <fieldset> <legend>Вводите только цифры и буквы</legend> Имя: <input type="text" name="user"> Пароль: <input type="password" name="pass"> <br> <input type="submit" value="Отправить"> </fieldset> </form> </body> </html>
cookie_set.php
<?php if (isset($_POST["user"])) echo "да<br>"; if (isset($_POST["pass"])) echo "да<br>"; ?>
I do not enter any form element, click send and display "yes" 2 times. in fact, $ _POST ["user"] and $ _POST ["pass"] should not be set unless values are entered into them, but the isset () function considers differently. Why?
But there is a script in which if you do not select the answer option, isset () will say that the element of the $ _POST array is not set. Below are two files
Two more files:
form2.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <form action="action2.php" method ="POST"> <fieldset> <legend>Каким языком программирования является PHP?</legend> Структурным <input type="radio" name="type" value="structure"><br> Процедурным <input type="radio" name="type" value="procedure"><br> Объектно-ориентированным <input type="radio" name="type" value="OOP"><br> <input type="submit" value="Отправить"> </fieldset> </form> </body> </html>
action2.php
<?php if (isset($_POST['type'])) { $answer = $_POST['type']; } else { $answer = NULL; } echo "answer = $answer<br>"; if ($answer != NULL) { if ($answer == "OOP") echo "Правильно!<br>"; else echo "Неправильно!<br>"; } else { echo "Вы не выбрали вариант.<br>"; }
action="cookie_set.php"anddoc.phpcode? - Rustam Gimranov