使用会话变量触发提交按钮

Triggering submit button using session variable

本文关键字:提交 按钮 变量 会话      更新时间:2023-09-26

我正在传递一个布尔值从一个页面到另一个使用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
 } 

 ?>

如果没有任何代码,就很难得到想要做的事情。如果你想让一个页面在会话变量为true时"回显"一些东西并显示页面内容,如果它不是,我建议以下最简单的方法:

    <?php
$session_value = $_SESSION["mySessionVariable"];
if { $session_value ) {
    // echo something 
}else {
    // include the php file with the "normal" page 
}
?>