5
<?php
if(isset($_POST['submit'])){
header('Location: http://www.rate.ee');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title>
        </title>
    </head>
    <body>
        <input type="submit" name="submit" id="submit" class="button" value="Submit"/>
    </body>
</html>

This is my code. Very simple, isn't it. But it doesn't work and I don't get it.. I always thought that PHP only executes when I load the page, but the other page where I use same code works very well without JS..

3 Answers 3

9

You need to wrap your button in a <form> tag:

<form action="" method="post">
<input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>
Sign up to request clarification or add additional context in comments.

Comments

3

You need a form surrounding the input.

<body>
<form action="welcome.php" method="post">
  <input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>
</body>
</html>

Comments

1

You have no form tag and even if you did it would need the method="post" attribute.

<form method="post" action="<?php echo $_SERVER[PHP_SELF]?>">
    <input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>

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.