我正在处理三个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