user1663978
user1663978

Reputation: 51

PHP submit button not working.

<?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..

Upvotes: 5

Views: 41515

Answers (3)

andrewsi
andrewsi

Reputation: 10732

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>

Upvotes: 9

j08691
j08691

Reputation: 207861

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>

Upvotes: 1

JvdBerg
JvdBerg

Reputation: 21856

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>

Upvotes: 3

Related Questions