Php 使用$\u POST显示数据

Php 使用$\u POST显示数据,php,html,forms,post,Php,Html,Forms,Post,我有工作代码,但我有一个关于通过表中格式化的$u POST发送数据的问题 在PAGE1.php上,我有以下代码: $printoutput .="<tr><td width='10%'> Item #". ($i+1) ."</td></tr> <tr width='20%'><td> " . $product_name . " --&nbsp;$" . $price . ".00</td></

我有工作代码,但我有一个关于通过表中格式化的$u POST发送数据的问题

在PAGE1.php上,我有以下代码:

$printoutput .="<tr><td width='10%'> Item #". ($i+1) ."</td></tr> 
<tr width='20%'><td>  " . $product_name . " --&nbsp;$" . $price . ".00</td></tr>
<tr><td width='40%'>" . $displayoptions . "</td>
<tr><td>&nbsp;</td></tr>";
编辑 另一种方法是链式方法,它将产生与我的原始答案相同的输出:

快速提示:

这:

可更改为:

$_SESSION['prodname'] = $product_name = $_POST['product_name'];
从POST变量获取信息。以上是一个简单的测试

第1页

<?php
session_start();
$_SESSION['prodname'] = $product_name = "Product name";
$_SESSION['prodcost'] = $price = "10";
$_SESSION['display'] = $displayoptions = "Display options";

// testing purposes only
// $price = $_SESSION['prodcost'];
// $displayoptions = $_SESSION['display'];

$printoutput .="<table><tr><td width='10%'> Item #". ($i+1) ."</td></tr> 
<tr width='20%'><td>  " . $_SESSION['prodname'] . " --&nbsp;$" . $_SESSION['prodcost'] . ".00</td></tr>
<tr><td width='40%'>" . $_SESSION['display'] . "</td>
<tr><td>&nbsp;</td></tr></table>";

// echo $printoutput;
$_SESSION['order'] = $printoutput;
echo $_SESSION['order']; // will echo on screen
<?php
session_start();
$product_name = "Product name";
$price = "10";
$displayoptions = "Display options";

$printoutput .="<table><tr><td width='10%'> Item #". ($i+1) ."</td></tr> 
                            <tr width='20%'><td>  " . $product_name . " --&nbsp;$" . $price . ".00</td></tr>
                            <tr><td width='40%'>" . $displayoptions . "</td>
                            <tr><td>&nbsp;</td></tr></table>";

$_SESSION['order'] = $printoutput;
echo $_SESSION['order'];
将打印:

第1项
产品名称--$10.00
显示选项

生成的HTML源代码:

<table><tr><td width='10%'> Item #1</td></tr> 
<tr width='20%'><td>  Product name --&nbsp;$10.00</td></tr>
<tr><td width='40%'>Display options</td>
<tr><td>&nbsp;</td></tr></table>
项目#1
产品名称--$10.00
显示选项

侧注:“我用
来抓取数据。”该符号距离
$
大约2-3英寸-你确定吗?很抱歉,输入错误没有问题。无永久性损伤;只是检查;-)你对第2页的代码有什么看法?这就是我们需要看到的。为什么不把你在第1页的代码放到第2页的条件语句中呢?或者类似的东西。我也许能弄明白,但等我搞定的时候,肯定会有人给出答案;-)
<?php
session_start();
if(isset($_POST['order'])) {
// $order = $_POST['order'];

$_SESSION['order'] = $printoutput;

$printoutput .="<table><tr><td width='10%'> Item #". ($i+1) ."</td></tr> 
<tr width='20%'><td>  " . $_SESSION['prodname'] . " --&nbsp;$" . $_SESSION['prodcost'] . ".00</td></tr>
<tr><td width='40%'>" . $_SESSION['display'] . "</td>
<tr><td>&nbsp;</td></tr></table>";

echo $printoutput; // Successfully printed out data from page 1
}

// You can place the mail() function below this
<?php
session_start();
$product_name = "Product name";
$price = "10";
$displayoptions = "Display options";

$printoutput .="<table><tr><td width='10%'> Item #". ($i+1) ."</td></tr> 
                            <tr width='20%'><td>  " . $product_name . " --&nbsp;$" . $price . ".00</td></tr>
                            <tr><td width='40%'>" . $displayoptions . "</td>
                            <tr><td>&nbsp;</td></tr></table>";

$_SESSION['order'] = $printoutput;
echo $_SESSION['order'];
<?php
session_start();
if(isset($_POST['order'])) {
  $order = $_POST['order'];
}

echo $_SESSION['order'];
<table><tr><td width='10%'> Item #1</td></tr> 
<tr width='20%'><td>  Product name --&nbsp;$10.00</td></tr>
<tr><td width='40%'>Display options</td>
<tr><td>&nbsp;</td></tr></table>