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

次の 2 つの方法で実行できます。

POST1)変数を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 に答える