2016-06-30 38 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

有一些計算髮生在重定向頁面上,只有當提交按鈕被觸發時,重定向頁面的輸出纔會被回顯! –