2012-09-11 87 views
3
<?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> 

這是我的代碼。很簡單,不是嗎。但它不起作用,我不明白..我一直認爲,PHP只執行當我加載頁面,但其他頁面,我使用相同的代碼工作得很好,沒有JS ..PHP提交按鈕不起作用。

回答

3

您需要圍繞輸入的表單。

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

你沒有表格標籤,即使你做了它,也需要method =「post」屬性。

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

你需要用一個<form>標記您的按鈕:

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

十分感謝大家,現在我會記住這一點! – user1663978