1

我的页面接收到我用 $_post 检索的数据。我显示了一些数据,在页面底部我的按钮必须将数据保存到 mysql。我可以将表单提交到下一页,但是我如何访问我通过 post 检索到的数据呢?可以说我有以下代码(实际上有更多变量..):

<?php
$v= $_POST["something"];
echo $v;
echo "Is the following information correct? //this would be at the bottom of the page with the buttons
?>
<input type="button" value="submit data" name="addtosql">
4

2 回答 2

0

你可以通过两种方法来做到这一点:

1)您可以将POST变量保存在hidden字段中。

<input type="hidden" name="somevalue" value="<?php if(isset($_POST["something"])) echo $_POST["something"];?>" >

隐藏值也将在FORM提交时传递到操作页面。在该页面中,您可以使用

echo $_POST['somevalue'];

2) 使用SESSION

您可以将值存储在任何其他页面中SESSION并可以在任何其他页面中访问。

$v= $_POST["something"];
session_start();
$_SESSION['somevalue']=$v;

并在下一页访问SESSION变量中使用,

session_start();
if(isset($_SESSION['somevalue']))
   echo $_SESSION['somevalue'];
于 2014-09-25T10:37:45.720 回答
0

看一看。下面的每件事都应该在单个 php 页面上

  // first create a function

     function getValue($key){
        if(isset($_POST[$key]))
            return $_POST[$key];
        else
           return "";
   }


   // process your form here
       if(isset($_POST['first_name']){
         // do your sql stuff here.
      }

 // now in html 

   <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="text"  name="first_name"  value="<?php echo getValue("first_name"); ?>" />
         <input type="submit" />
   </form>
于 2014-09-25T10:42:40.313 回答