Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP submit button not working.

Tags:

html

php

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

like image 513
user1663978 Avatar asked Sep 11 '12 20:09

user1663978


2 Answers

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>
like image 191
andrewsi Avatar answered Oct 23 '22 09:10

andrewsi


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>
like image 3
JvdBerg Avatar answered Oct 23 '22 09:10

JvdBerg