0
    <?php

Function runSearch($name)
{
If(isset($_POST['submit']))
    {
    $name = $_POST['name'];
    echo "Results for " .$name;
    }
}

?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   Search String: <input type="text" name="name"><br>
   <input type="submit" name="submit" value="Submit"><br>
</form>

This code is suppose to display what is entered into the Search String text box. When I don't use a function it works fine. But as soon as I place the code into the function runSearch there is no output. I'm new to php can an argument be sent to a php function and then displayed on the screen?

1 Answer 1

3

you need to call your function, otherwise nothing will happen. Also you need to removed the $name-parameter:

<?php

function runSearch()
{
    if(isset($_POST['submit']))
    {
        $name = $_POST['name'];
        echo "Results for " .$name;
    }
}
runSearch();
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   Search String: <input type="text" name="name"><br>
   <input type="submit" name="submit" value="Submit"><br>
</form>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.