2017-04-01 95 views
7

在頁面上我有幾個提交輸入(按鈕),具有以下isset條件:如果/ elseif的'isset`多次提交輸入不起作用

if (isset($_POST[ 'noranTelChecks' ])) { // user requested noranTelCheck sheet 
    header('location: noranTelChecks.php'); 

    } elseif (isset($_POST[ 'juniperChecks' ])) { // user requested noranTelCheck sheet 
    header('location: juniperChecks.php'); 

    } elseif (isset($_POST[ 'mpr95001Checks' ])) { // user requested noranTelCheck sheet 
    header('location: mpr95001Checks.php'); 
} // close IF 

但無論什麼按鈕被點擊的頁面總是重定向到第一個IF條件所指的鏈接。如果我改變引用鏈接的順序,它始終是頁面重定向到的第一個條件的鏈接。

上面的代碼導致這個問題有什麼問題,因爲我在過去的其他頁面上完成了這項工作,它工作正常嗎?

+1

檢查'$ _POST'在所有情況下 –

+0

雖然我不知道原因是什麼,你可以嘗試使用的目標位置的變量('$ location')在你的if/elseif中,然後只需要調用一次'header('location:'。$ location);'在它之外 - 也許這有助於某種程度? – domsson

+1

你給你的輸入按鈕命名?如果你給出名字,只有點擊輸入應該發送。在這裏看到答案http://stackoverflow.com/questions/11929471/how-do-i-use-two-submit-buttons-and-differentiate-between-which-one-was-used-to – Incognito

回答

1

我猜你的按鈕有例如

<input type="submit" id="noranTelChecks" name="noranTelChecks" value="Button 1"/> 

,所以你可以使用值,而不是名稱或ID設定值。該代碼將是如下

if (isset($_POST["Button 1"])) 
{ 
    header('location: noranTelChecks.php'); 
}