在PHP中使用GET提交页面时保存信息

时间:2015-08-08 13:23:08

标签: php html html5

public function listen(GetResponseEvent $event){
  // in your listeners main function
  $request = $event->getRequest();
  $route = $request->attributes->get('_route');
  if($route != 'your_ajax_check_route'){
    // update the session and etc.
    // retrieve what you store here in your other listener.
  }
}

因此,在移至<form method='get' action='y.php'> <div> <input type='text' id='txtName' name='txtName'/> <input type='submit' value='submit' id='submit'/> </div> </form> <?php if ($_SERVER['REQUEST_METHOD'] == 'GET') { if (isset($_GET['btnSave'])) { $name=isset(($_GET['txtName'])?isset($_GET['txtName']:''); //then Logic of insert goes here } } ?> 之前,必须保存记录。 但我无法获得y.php值,作为$name的操作。 如何在文本框中显示包含值的y.php

如果您将操作更改为此(相同/当前)页面记录将转到数据库而没有任何缺陷或错误。

3 个答案:

答案 0 :(得分:0)

试试这段代码,

<form method='get' action=''>
    <div>
        <input type='text' id='txtName'  name='txtName'/>
        <input type='submit' value='submit' id='submit'/>
    </div>
</form>
<?php
    if ($_SERVER['REQUEST_METHOD'] == 'GET') 
    {
        if (isset($_GET['txtName'])) {
        $name=$_GET['txtName'];
        //then Logic of insert goes here
    }
}

?>

答案 1 :(得分:0)

尝试使用post方法,并相应地更改代码,试试这个:

<form method='post' action=''>
<div>
 <input type='text' id='txtName'  name='txtName'/>
 <input type='submit' value='submit' id='submit' name='submit'/>
</div>
</form>
<?php

    if (isset($_POST['submit'])) {
      $name=$_POST['txtName'];
     //then Logic of insert goes here
    //redirect to y.php with name value
    echo "<script>window.open('y.php?user=$name','_self')</script>";
       }

             ?>

然后使用$nme = $_GET['user'];获取y.php

$name的值

答案 2 :(得分:0)

我建议您使用方法帖子。您可以像这样编码

<form method='post' action=''>
    <div>
        <input type='text' id='txtName'  name='txtName'/>
        <input type='submit' value='submit' id='submit'/>
    </div>
</form>
<?php
    if(isset($_POST['txtName'])){            
    $name =$_POST['txtName'];    
    echo $name;
    }

?>

如果您想在另一个文件中使用该值,则可以使用该会话。

我希望能解决你的问题

相关问题