2016-06-30 24 views
0

我使用PHP中的会话变量从一个页面传递布尔值到另一个页面,第二页是为了显示结果,如果提交表单,我想触发提交按钮,如果布尔是真实的,并自动显示结果,(回声),但如果错误,页面应显示为其意图。由于我是新来的,请帮忙!另外,我对Ajax并不熟悉。使用会话变量触发提交按钮

感谢

<?php 
session_start(); 
if(isset($_SESSION['answer'])) { 

$v11=$_SESSION['answer'];//boolean value 
} 

$q=100; 
$f=200; 
$r=300; 



    ?> 
    <link rel="stylesheet" type="text/css" href="../../styles/messages.css"    /> 

    <html> 

    <table cellpadding="0" cellspacing="0" border="0"> 
<form action="" name = "page0" method="GET" enctype="multipart/form- data"> 
    <tr > 
    <td colspan= > ID </td><br> 
<td colspan="2" size="30"> NAME </td> 
<td colspan="3" size="50" > MACH </td> 

</tr> 

<tr> 
<td colspan=><input type="text" name="ID" class="rw" value="<?php  $phpvar=$v11; echo $phpvar; ?>"></td> 
<td colspan="2" ><input type="text" name="NAME" class="rw" size="30" value="<?php $phpvar=$f; echo $phpvar; ?>"></td> 
<td colspan="2"><input type="text" name="MACH" class="rw" size="70" value="<?php $phpvar=$r; echo $phpvar; ?>"></td> 

</tr> 
<input type="submit" button class="button" value="Calculate" name="second_call" onclick= "document.write('<?php hello(); ?>');" /> 
</form> 
</table> 
</html> 
    <?php 
function hello() 
    { 
    //some operation using values q, f, r 
    echo(result); 
    //i want this echo to work when i click submit on the previous page from  where im redirecting here if v11=true 
} 


?> 
+0

你能后的样本你的代码? – meucaa

+0

我编辑过! –

回答

0

这是很难得到你想要的,没有任何的代码做什么。 如果你想有一个页面,以“回声”的东西,如果会话变量是“真” 并显示该网页内容,如果不是的话,我建议以下最简单的办法:

<?php 

$session_value = $_SESSION["mySessionVariable"]; 

if { $session_value) { 
    // echo something 
}else { 
    // include the php file with the "normal" page 
} 

?> 
+0

有一些计算发生在重定向页面上,只有当提交按钮被触发时,重定向页面的输出才会被回显! –