How to make the right look?

<?php echo "Привет, $_GET['name'] Вам $_GET['age'] лет "; ?> 

Second file

 <html><body> <form action="lost.php" method="post"> Введите имя: <input type=text name="name"><br> Введите возраст: <input type=text name="age"><br> <input type=submit value="GO!"> </form> </body></html> 
  • @bekzat, To format the code, select it with the mouse and click on the button 101010 of the editor. - angry
  • For some reason, when the isset command was deleted in the "Enter age" line, then the age began to be displayed correctly - user330209

4 answers 4

 <?php echo "Привет, $_POST['name'] Вам $_POST['age'] лет "; ?> 
     <form action="lost.php" method="get"> 

    POST to GET change!

    • Two solutions, and both are correct)) - Andrey Arshinov
    • Well, then yes ... - Artem

    ... but generally unlearn unnecessarily insert variables into strings. If you get used to it, there will be misunderstandings with objects and keys of arrays. Plus do not let variables without verification.

     <?php $name = isset($_POST['name']) ? $_POST['name'] : 'Unknown'; $age = isset($_POST['age']) and $_POST['age'] > 0 ? (int) $_POST['age'] : 'Unknown'; echo 'Привет,' . $name . ', Вам ' . $age . ' лет '; ?> <html><body> <form action="lost.php" method="post"> Введите имя: <input type=text name="name"><br> Введите возраст: <input type=text name="age"><br> <input type=submit value="GO!"> </form> </body></html> 

    Like that)

      By the way, note: there is also a superglobal array $ _REQUEST which contains $ _GET and $ POST. It is probably rarely used - in technical cases when it doesn't matter how the parameters are transmitted.

      • No, it is used simply to check whether any parameters were passed or not :) - Artem