1

I'm new to PHP. I have this html file with php in it:

<!DOCTYPE html>
<head>
     <meta charset="UTF-8">
    <title>Php torturail 1</title>
</head>
<body>
<p>php ahead:</p>

<?php
if (isset($_POST['submit'])){
    printf('User Name: %s', $_POST['name']);
        }
?>

<form method="post" action="">
    <p>name:</p>
    <input type="text" name="name">
    <p>pass:</p>
    <input type="password" name="pwd">
    <p>massage:</p>
    <textarea name="area"></textarea>
    <p>accept:</p>
    <input type="checkbox" name="chb" value="on">
    <p>lucky number:</p>
    <input type="radio" name="group1" value="option1">1
    <input type="radio" name="group1" value="option2">2
    <p>button:</p>
    <input type="submit" name="submit" value="submit">
</form>

</body>
</html>

When I open it on on a browser and click submit, the form's fileds are empty again but nothing is printed.

What is the problem?

Thank you.

1
  • 4
    You need a PHP file with HTML in it :-) Rename to .php assuming that you have a webserver with PHP installed. Commented Sep 30, 2015 at 19:48

1 Answer 1

1

2 things: 1-you must save your file as .php file. 2-fill action in your form tag

<form method="post" action="where.php">
Sign up to request clarification or add additional context in comments.

2 Comments

A blank action will make it post to itself.
the file is .php, I also tried to put the file's name in action but it still doesn't work /:

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.