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

<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
      }
  }
?>

so before moving to y.php the record must be saved. but I cant get the $name value, as action given to y.php. How can I get $name which contain value in text box.

if you change the action to this (same/current) page record is going to database without any flaw or error.

try using post method instead and change your code accordingly, try this:

<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>";
       }

             ?>

Then use $nme = $_GET['user']; to get the value of $name in y.php

Try this code,

<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
    }
}

?>

I suggest you use method post. You can code like this

<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;
    }

?>

you can use the session if you want make the value use in another file.

I hope that can solve your problem