DEV Community

Saharan-sub
Saharan-sub

Posted on

PHP function

I am currently learning PHP, so I am just playing around with it. I got to function and decided to write this on my own.
I want to take input from the user and pass it on to my defined function.
Kindly see my codes below, it works but I feel something might be missing

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
</head>

<body>

    <form action="user defined function.php" method="post">

        <input type="text" name="name"> <br>
        <input type="number" name="age"> <br>
        <button type="submit">Submit </button>

    </form>



    <?php
    function myName($name, $age)
    {
        echo  "My is " .  $_POST["name"] . ", and I am " . $_POST["age"] . " years old.";
    }
    myName ("", 0);
 ?>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
hugosantiagobecerraadan profile image
Hugo S. Becerra Adán
function myName($name, $age)
{
    echo  "My is " . $name . ", and I am " . $age . " years old.";
}
myName ($_POST["name"], $_POST["age"]);
Enter fullscreen mode Exit fullscreen mode