-1

This is my first page nfdata.php

<form action='drop.php' method='get'>
<tr>
<td ><input type="radio" name="radio" value="DGSTO 1">DGSTO 1</td>
<td><input type="submit" name="sub" value="Submit">

This is my 2nd page drop.php

<html>
<form id="form" action"drop.php" method="get">
    <select id="office" name="code">

 <?php
     include 'sql.php';
     if($div = $_GET['radio'])
  {
                  $div = $_GET['radio'];
                     $query="SELECT off_code_nf From non_filer where div_code_nf='$div' group by off_code_nf";
                        $sql = mysql_query($query);
                       // $row = mysql_fetch_assoc($sql);
        //echo "<select name='to_user'>";
                            while ($row = mysql_fetch_assoc($sql))
       {
                                echo "<option value='". $row['off_code_nf'] ."'>" .$row['off_code_nf'] ."</option>" ;
                            }
                        //echo "</select>" ;
     }
 
 ?>
 </select>
 <input type="submit" name="sub" value="Submit" />
 <br><br>
 
 <?php
    include 'sql.php';
 $inventory = $_GET['code'];
 $query= "SELECT * FROM non_filer WHERE off_code_nf = '$inventory' "; 
 $result = mysql_query($query);
 if ($inventory = $_GET['code'])
    { 
         echo "<table border='1'>
               <tr>
               <th>State Code</th>
               <th>GSTIN</th>
               
      </tr>";
    }
 while ( $row = mysql_fetch_assoc( $result ) )
     {
          $a = $row['state_code_nf'];
       $b = $row['gstin_nf'];
       Print("<tr >");
         print("<td >$a</td>");
         print("<td >$b</td>");
     }
   print("</table>");
?>
</html>
I used get method in nfdata.php and get value of radio button in second page drop.php where it is selecting data from data base. but after selecting value from drop down When I am clicking on submit in drop.php page the value of drop down is not coming because there is new get method. so how to keep the value of first get method
  • Maybe you can store the `$_GET` values in a `$_SESSION`, which you could use again despite the submission of the second page? – Manav Apr 03 '18 at 09:50
  • Don't use mysql_* anymmore, it's deprecated. And you're vulnerable to SQL-injection here, use prepared statements for your queries. – jonas3344 Apr 03 '18 at 09:51
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) that has been [removed](http://php.net/manual/en/mysql.php) from PHP. You should select a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Apr 03 '18 at 09:53
  • Your HTML is [invalid in a way that could break your code](https://stackoverflow.com/questions/5967564/form-inside-a-table). Use [a validator](https://validator.nu/). – Quentin Apr 03 '18 at 09:54

1 Answers1

0

<html>
<form id="form" action"drop.php" method="get">
    <select id="office" name="code">

 <?php
     include 'sql.php';
$radioVal = $_GET['radio'];
     if($div = $_GET['radio'])
  {
                  $div = $_GET['radio'];
                     $query="SELECT off_code_nf From non_filer where div_code_nf='$div' group by off_code_nf";
                        $sql = mysql_query($query);
                       // $row = mysql_fetch_assoc($sql);
        //echo "<select name='to_user'>";
                            while ($row = mysql_fetch_assoc($sql))
       {
                                echo "<option value='". $row['off_code_nf'] ."'>" .$row['off_code_nf'] ."</option>" ;
                            }
                        //echo "</select>" ;
     }
 
 ?>
 </select>
<input type="hidden" name="radio_val" value="<?=$radioVal?> />
 <input type="submit" name="sub" value="Submit" />
 <br><br>
 
 <?php
    include 'sql.php';
 $inventory = $_GET['code'];
 $query= "SELECT * FROM non_filer WHERE off_code_nf = '$inventory' "; 
 $result = mysql_query($query);
 if ($inventory = $_GET['code'])
    { 
         echo "<table border='1'>
               <tr>
               <th>State Code</th>
               <th>GSTIN</th>
               
      </tr>";
    }
 while ( $row = mysql_fetch_assoc( $result ) )
     {
          $a = $row['state_code_nf'];
       $b = $row['gstin_nf'];
       Print("<tr >");
         print("<td >$a</td>");
         print("<td >$b</td>");
     }
   print("</table>");
?>
</html>

Use $_GET['radio_val'] when click on submit button on second page