我正在處理三個PHP文件。兩個用作網頁,另一個用於外部服務器端腳本。服務器端腳本包含在兩個網頁文件中,我想要做的是在第一頁上有一些按鈕,並根據所點擊的是哪一個按鈕,用數據填充第二頁然後重定向到它。爲什麼PHP varible仍未定義?
使用下面的代碼,想法是拿起按鈕單擊,找出哪個按鈕被點擊,然後調用該函數來運行正確的查詢並設置所需的變量。我不明白爲什麼變量沒有被設置。
感謝任何人看着這個!
第一頁的按鈕(的index.php):
<input type="submit" id='details' name='details' value='Submit'/>
二頁面,當頁面加載變量未定義:
<h4><?php echo $selected_button; ?></h4>
外部腳本:
function detailBuilder(){
$selected_button = "Option One";
//header('Location: details.php'); if this is here, the page still redirects but the variable doe not get set
//More will happen here once it works
}
if(isset($_POST['details'])){
detailBuilder();
header('Location: details.php');
}
這是你接下來閱讀什麼:http://php.net/manual/en/tutorial.forms。 php - 教程中的第一個鏈接... – 2015-02-17 22:03:12
你知道當一個頁面發生變化(標題位置)時,所有腳本都會終止,並開始一個新的過程,對嗎?您需要將其作爲get var,cookie或其他臨時存儲來傳遞。 location:details.php?selected_button = option-one ...或者其他一些 – 2015-02-17 22:03:16
這段代碼沒有意義,所以它不清楚你打算做什麼。 – developerwjk 2015-02-17 22:03:18