0

I have a simple form and I'm trying to pass the form variable to php and output the value. I have tried to solve this myself with the almighty google but wasn't successful. The html form code is as follows

<html>
<head>
    <title>Form</title>
</head>

<body>
    <form method="post" action="test1.php">
    <input type="text" name="username">
    <input type="submit">
    </form>

</body>
</html>

Then the php to handle the form is:

<html>
<head>
    <title>Form</title>
</head>

<body>

    <?php

        echo "<h1>Hello " . $_POST["username"] . "</h1>";

    ?>

</body>
</html>

The output I'm getting no matter what I type into the html form is , Hello " . $_POST["username"] . ""; ?>

I don't know why it also outputs the ending semi colon and ending php tag also, maybe this is evidence of what's going wrong here?

Renaissance
  • 798
  • 5
  • 15

2 Answers2

3

PHP is

  • misconfigured or
  • not configured or
  • not working or
  • not working within HTML files.

You have to configure your webserver that it parses PHP inside HTML files, see here for example:

=> Server not parsing .html as PHP

Community
  • 1
  • 1
djot
  • 2,952
  • 4
  • 19
  • 28
-3

The syntax is fine, try to write a sample code snippet like below

<?
$a = "hello word!";
echo $a;
?>

and check if php is working.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150