title: retrive value from database using radio button in php and only displaying the field name which is selected not others
body: <p>I think the answer to this question can be very simple but I'm not able to get the basic idea of getting my answer.</p>
  
  <p>Context:</p>
  
  <p>I made a simple page of booking movie ticket through radio button and able to store and retrieve value and after retrieving the value.</p>
  
  <p>I have added radio button in that value and then tried to retrieve the value of single field in other page but the I only get one value displayed not other one.</p>
  
  <p>The value for the first row in one table is only displayed and does not matter which value is selected.</p>
  
  <p>Markup:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;/head&gt;
  &lt;body bgcolor= cyan&gt;
  &lt;form method="post" action="sqlmovie1.php"&gt;
  &lt;table cellpadding="20" cellspacing="40" bgcolor="red"width="100%"&gt;&lt;center&gt;
  &lt;tr&gt;
  &lt;td&gt; &lt;center&gt;&lt;font size=+5 color="MAGENTA"&gt;BOOK TICKET &lt;/FONT&gt;&lt;center&gt;
  &lt;/td&gt;&lt;/tr&gt;&lt;/center&gt;
  &lt;/table&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;center&gt;
  &lt;table border="1" cellspacing="10" cellpadding="5"&gt;
  &lt;tr&gt;&lt;td&gt;
  
  audi1: &lt;input type = "radio" name="audi" value="1"&gt;
  
  audi2: &lt;input type = "radio" name="audi" value="2"&gt;
  
  audi3: &lt;input type = "radio" name="audi" value="3"&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;CENTER&gt;
  &lt;input type="submit" value ="submit"&gt;&lt;/CENTER&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/center&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/html&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>php code is sqlmovie1.php</p>
  
  <pre><code>&lt;?php
  $cxn = mysqli_connect("localhost","root","","movie");
  if(mysqli_connect_errno())
  {
      echo "invalid login :",$mysqli_connect_error();
  }
  
  $name = $_POST['audi'];
  echo "&lt;html&gt; &lt;body&gt; 
  &lt;table border='1'&gt;
  &lt;tr&gt;&lt;td&gt; movie name &lt;/td&gt;
  &lt;td&gt; timing&lt;/td&gt;
  &lt;td&gt; ticket price &lt;/td&gt;
  &lt;td&gt; book movie &lt;/td&gt; &lt;/tr&gt;";
  
  if(isset($name) &amp;&amp; ($name =="1"))
  {
      $sql="select * from  movie1";
      $result=mysqli_query($cxn,$sql);
      $column_count = mysqli_num_fields($result);
  
      if(mysqli_num_rows($result)!="")
      {
          while($row=mysqli_fetch_array($result))
          {
              echo("&lt;tr&gt;");
              for ($column_num = 0;$column_num &lt; $column_count;$column_num++)
                  echo "&lt;TD&gt;$row[$column_num]&lt;/TD&gt;\n";
                  echo "&lt;td&gt;&lt;form method='post' action ='moviebooked1.php'&gt;  &lt;input type ='radio' name = 'book1' value='1'&gt;&lt;/td&gt;&lt;td&gt;&lt;input type = 'submit' name = 'submit' value = 'book show'&gt;&lt;/form&gt;&lt;/td&gt;";
                  echo("&lt;/TR&gt;\n");
           }    
      }
  
  //echo "&lt;form method='post' action='moviebooked1.php'&gt;  &lt;input type ='radio' name = 'book1' value='1'&gt;&lt;input type='submit' name='submit' value= 'book show'&gt;&lt;/form&gt;";
  }
  elseif(isset($name) &amp;&amp; ($name=="2"))
  {
      $sql="select * from  movie2";
      $result=mysqli_query($cxn,$sql);
      $column_count = mysqli_num_fields($result);
      if(mysqli_num_rows($result)!="")
      {
          while($row=mysqli_fetch_array($result))
          {
              echo("&lt;TR ALIGN=LEFT VALIGN=TOP&gt;");
              for ($column_num = 0;$column_num &lt; $column_count;$column_num++)
                  echo("&lt;TD&gt;$row[$column_num]&lt;/TD&gt;\n");
                  echo "&lt;td&gt;&lt;form method='post' action ='moviebooked1.php'&gt;  &lt;input type ='radio' name = 'book2' value='2'&gt;&lt;/td&gt;&lt;td&gt;&lt;input type = 'submit' name = 'submit' value ='book show'&gt;&lt;/form&gt;&lt;/td&gt;";
              echo("&lt;/TR&gt;\n");
          }
      }
  }
  elseif(isset($name) &amp;&amp; ($name=="3"))
  {
      $sql="select * from  movie3";
      $result=mysqli_query($cxn,$sql);
      $column_count = mysqli_num_fields($result);
      if(mysqli_num_rows($result)!="")
      {
          while($row=mysqli_fetch_array($result))
          {
              echo("&lt;TR ALIGN=LEFT VALIGN=TOP&gt;");
              for ($column_num = 0;$column_num &lt; $column_count;$column_num++)
                  echo("&lt;TD&gt;$row[$column_num]&lt;/TD&gt;\n");
                  echo "&lt;td&gt;&lt;form method='post' action ='moviebooked1.php'&gt;  &lt;input type ='radio' name = 'book3' value='3'&gt;&lt;/td&gt;&lt;td&gt;&lt;input type = 'submit' name = 'submit' value = 'book show'&gt;&lt;/form&gt;&lt;/td&gt;";
                  echo("&lt;/TR&gt;\n");
  
          }
      }
  }
  echo "&lt;/table&gt;";
  
  ?&gt;
  </code></pre>
  
  <p>I applied different methods in the table <code>movie1 movie2</code> and <code>movie3</code> but didn't got anything new and problem lies here and above code.</p>
  
  <p>In <code>movie1</code>, </p>
  
  <p>I stored 3 rows <code>moviename, movietiming</code> and <code>ticketprice</code>, </p>
  
  <p>Values are <code>row1 is kick 11.00am 150</code>, <code>row2 is hulk 12.00pm 150</code> <code>row3 is fastandfurious 1pm 150</code>.</p>
  
  <p>If I try to retrive the answer the name of the movie for which I booked, its not giving me the correct movie name it only displays the name of first movie in all the table.</p>
  
  <p>I'm booking through the radio button. How can I get my right movie name which I selected </p>
  
  <p>Aa big tnx in advance for the help, problem is very very small but question is big.</p>
  
  <p>Here is my last code <code>moviebooked1.php</code>:</p>
  
  <pre><code>&lt;?php
  $cxn=mysqli_connect("localhost","root","","movie");
  if(mysqli_connect_errno())
  {
  echo "invalid login :",$mysqli_connect_error();
  }
  if (isset($_POST['book1']))
  {
  $sql="select moviename from movie1";
  $result=mysqli_query($cxn,$sql);
  if($row=mysqli_fetch_array($result))
  {
  foreach($row as $value['moviename'])
  {
  echo " your show for ,$row['moviename'],"has been booked";}
  
  }}
  
  elseif (isset($_POST['book2']))
  {
  $sql="select moviename from movie2";
  $result=mysqli_query($cxn,$sql);
  if($row=mysqli_fetch_row($result))
  {
  echo "your ticket for",  $row['moviename'], "movie has been booked";
  echo "&lt;br&gt;";
  }
  if (isset($_POST['book3']))
  {
  $sql="select moviename from movie3";
  $result=mysqli_query($cxn,$sql);
  if($row=mysqli_fetch_array($result))
  {
  echo "your ticket for",  $row['moviename'], "movie has been booked";
  echo "&lt;br&gt;";
  }
  ?&gt;
  </code></pre>