PHP submit button does not work.

<?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, right. But this does not work, and I do not understand. I always thought that PHP only runs when the page loads, but on another page where I use the same code, it works very well without JS ..

+5
source share
3 answers

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

<form action="" method="post">
<input type="submit" name="submit" id="submit" class="button" value="Submit"/>
</form>
+9
source

You need a shape surrounding the entrance.

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

You do not have a form tag, and even if you did, he 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>
+1
source

All Articles