douyan0732 2017-06-23 04:01
浏览 32
已采纳

是否可以在HTML中打印PHP生成的结果? [关闭]

I am doing a program that does some calculations and in the end generates the result assign to the variable $result, the data is entered using a web form <form method = "POST" action = "file.php">

For example in <form> / web form the user can enter numbers using text fields and it submits to file.php and file.php calculates value and assign to $result variable.

Eg. $result = $value1 + $value2

And what I want is that in the HTML page (even if you have to reload the page) show something like:

"Your value equals 5"

Where 5 is what I left in $result.

What I want to know is that what is the convenient / right way of displaying the results in HTML page in PHP.

  • 写回答

1条回答 默认 最新

  • duanpiangeng8958 2017-06-23 04:12
    关注

    You can do it like this:

    On your file.php

    <?php 
         $value_1 = intval($_POST['value1']);
         $value_2 = intval($_POST['value2']);
    
         $result = $value_1 + $value_2;
    
         echo "Your value equals ".$result;
    
     ?>
    

    You can echo it to your file.php

    But if you want to redirect it to other html page with php you can create a session variable to save your $result just like this:

    $_SESSION['result'] = $result; //the sum of the val_1 and val_2
    

    Then just echo this to your other html page.

    echo $_SESSION['result'];
    

    Hope it will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程