title: PHP/HTML - Read table row where radio button is active after form submit
body: <p>I am trying to create a webpage where a table lists a bunch of meals for a whole month. I want to be able to use a <strong>radio button</strong> at the <strong>beginning of each row</strong> ( 1 row - one day ) to select which meal will be the next one.
  The reasoning behind this is that I have another webpage which will display "next meal : XXX" where XXX is read from the database ( something like "where nextmeal=1" ).
  So basically what I want is that when <strong>I activate one of my radio buttons</strong> the meal in this line should get a nextmeal=1 in the database entry. 
  <strong>Database table</strong> has the following <strong>columns = date,meat,veggie,nextmeal</strong>
  I tried some suggestions on how to send active radio button values to the server but I wasn't able to paste the correct date to the server to do the correct query.</p>
  
  <p>Source code for the table webpage :</p>
  
  <pre><code>&lt;?php
  require_once 'db_config.inc.php';
  require_once 'functionsgerichte.php';
  $db = new mysqli($db_server,$db_user,$db_password,$db_database);
  if(!empty($_GET['monat'])) {$monat = $_GET['monat'];} //define default_month
  else $monat = 14;
  if(!empty($_GET['jahr'])) {$activ_year = $_GET['jahr'];} //define  default_year
  else $activ_year = 2010;
  ?&gt;
  &lt;html&gt;
  &lt;style&gt;
  #gerichtetext {
  width: 100%;
  padding: 5px;
  margin: 0px;
  background-color:rgba(0, 0, 0, 0);
  color:black;
  border: none;
  outline:none;
  }
  input[type=radio] {
  width: 100%;
  padding: 5px;
  margin: 0px;
  height: 50%;
  
  }
  
  &lt;/style&gt;
  
  &lt;link rel="stylesheet" href="../includes/jqueryui/jquery-ui.min.css"&gt;
  
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"&gt;&lt;/script&gt;
  
  &lt;script src="../includes/jqueryui/jquery-ui.min.js"&gt;&lt;/script&gt;
  
  &lt;body bgcolor = '#e3e3e3'&gt;
  
  &lt;form action style='float:left'&gt;
  &lt;select name='monat' size='1'&gt;
  
  &lt;?php 
          $monate = array("","Januar","Februar","M&amp;auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");  //
          for($i=1; $i&lt;=12;$i++)
          {
              if($monat== 14) echo "&lt;option value=".$i."&gt;". $monate[$i] ."";
              else if($i == $_GET['monat']) echo "&lt;option selected='selected' value=".$i."&gt;". $monate[$i] ."";
              else echo "&lt;option value=".$i."&gt;". $monate[$i] ."";
          }
          echo "&lt;/select&gt;";
          $jahrabfrage="SELECT DISTINCT YEAR(timestamp) as jahre FROM essenslog ORDER BY year(timestamp)";
          $jab = mysqli_query($db,$jahrabfrage);
          echo "&lt;select name='jahr' size='1'&gt;";
          while($year = mysqli_fetch_object($jab))
          {
              if($year-&gt;jahre == $_GET["jahr"]) echo "&lt;option value='$activ_year' selected='selected'&gt; $year-&gt;jahre&lt;/option&gt;"; 
              else echo "&lt;option value='$year-&gt;jahre'&gt;$year-&gt;jahre&lt;/option&gt;";
          }
      ?&gt;
  &lt;/select&gt;
  &lt;input type='submit' value='send'&gt;
  
  &lt;/form&gt;
  
  &lt;?php
  
  $month=$_GET['monat'];  $year = $_GET['jahr']; // Variablen übergeben 
  
  $unixtime = "$year-$month-21 12:00:00";         //21. Tag des Monats des Jahres
  
  $unixmonat = date("t", strtotime($unixtime));   //Ermittlung der Anzahl der Tage des Monats des Jahres
  
  $Tage = Array_Fill(1, $unixmonat,42);           //Auffüllen eines Arrays (von 1-Anzahl der Tage eines Monats)
  
  //Ermittlung der Anzahl der DB-Einträge
  
  $groesse = count($alle);
  
  $tmp = array_keys($Tage);
  
  $LetzterTag = end($tmp)+1;
  
  $temptimer = 0;
  
  $AlleTage = array();
  
  for($i=0; $i&lt;$LetzterTag;$i++) //Erstellung von je einem Object je Tag
  
  { 
  $ActiveDay[$i] = new NeuerTag;      
  array_push($AlleTage,$ActiveDay[$i]);
  
  }       
  
  $i = 0; //initialisieren des Tagecounters
  
  ?&gt;
  
  &lt;form action='gericht2db.php' id='MyForm' method='get' &gt;
  
  &lt;input type='hidden' value='&lt;?php echo $month; ?&gt;' name='monat'/&gt;
  
  &lt;input type='hidden' value='&lt;?php echo $year; ?&gt;' name='jahr'/&gt;
  
  &lt;input type='hidden' value='&lt;?php echo $LetzterTag; ?&gt;' name='letztertag'/&gt;
  
  &lt;input type='hidden' value='' name='radio_row'/&gt;
  
  &lt;input style='float:right' onclick='check()' id='submit-button' type='submit' value='SPEICHERN'/&gt;
  
  &lt;table border ='1' width ='100%' height ='100%' style='clear:both'&gt;&lt;tr bgcolor='#666666' style='color:white'&gt;&lt;td width='5%'&gt;NächstesEssen&lt;/td&gt;&lt;td width='10%'&gt;Wochentag&lt;/td&gt;&lt;td width='10%'&gt;Datum&lt;/td&gt;&lt;td width='35%'&gt;Fleisch&lt;/td&gt;&lt;td width='35%'&gt;Vegetarisch&lt;/td&gt;&lt;/tr&gt;
  &lt;?php
  for($i=1; $i&lt;$LetzterTag;$i++)
  {
      $time = "$year-$month-$i";
      if(date('l',strtotime($time)) == "Saturday" ||date('l',strtotime($time)) == "Sunday" || in_array(strtotime($time), $Freietage)) $ActiveDay[$i]-&gt;Feiertag = true;
      if($ActiveDay[$i]-&gt;Begin == 0)
      {
          $color = "#969696";
          if(date('l',strtotime($time)) == "Saturday" ||date('l',strtotime($time)) == "Sunday" || in_array(strtotime($time), $Freietage))
          {
              $color = "#86191a";
              $fontcolor = "#a1a1a1";
          }
          else
          {
              $color = "#969696";
              $fontcolor = "black";
          }           
          echo "&lt;tr bgcolor='$color' style='color:$fontcolor'&gt;";  
          echo "&lt;td &gt;";
          if(date('l',strtotime($time)) == "Saturday" ||date('l',strtotime($time)) == "Sunday" || in_array(strtotime($time), $Freietage))
          {
              echo "&lt;/td&gt;";
          }
          else
          {
              echo "&lt;input type='radio' id='radio_".$i."' name='radio' value='radio_".$i."' /&gt;";
              echo "&lt;/td&gt;";
          }           
          echo "&lt;td&gt;".date('l',strtotime($time))."&lt;/td&gt;";
          echo "&lt;td&gt;".date("d", strtotime($time)).".".date("m", strtotime($time)).".".date("Y", strtotime($time))."&lt;/td&gt;";
          $fleisch=fleisch(date("Y", strtotime($time))."-".date("m", strtotime($time))."-".date("d", strtotime($time)));
          $veggie=veggie(date("Y", strtotime($time))."-".date("m", strtotime($time))."-".date("d", strtotime($time)));
          $temp="fleisch_".$i ;
          echo "&lt;td &gt;";
          if(date('l',strtotime($time)) == "Saturday" ||date('l',strtotime($time)) == "Sunday" || in_array(strtotime($time), $Freietage))
          {
              echo "&lt;/td&gt;";
          }
          else
          {
              echo "&lt;input type='text' id='gerichtetext' name='".$temp."' value='".$fleisch."'/&gt;&lt;/td&gt;";
              echo "&lt;/td&gt;";
          }
          $temp="veggie_".$i ;
          echo "&lt;td&gt;";
          if(date('l',strtotime($time)) == "Saturday" ||date('l',strtotime($time)) == "Sunday" || in_array(strtotime($time), $Freietage))
          {
              echo "&lt;/td&gt;";
          }
          else
          {
              echo "&lt;input type='text' id='gerichtetext' name='".$temp."' value='".$veggie."'/&gt;&lt;/td&gt;";
              echo "&lt;/td&gt;";
          }
          echo "&lt;/tr&gt;";
      }
      echo "&amp;nbsp&lt;/td&gt;";
  
  
  }
  
  ?&gt;
  
  
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;/form&gt;
  
  &lt;script&gt;
  
  $('tbody').on('change', ':radio', function()
  
  {
  var line = $('input[name=radio]:checked').val();
  // alert(line);
  
  });
  
  &lt;/script&gt;
  
   &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;
  
  
  $.ajax({
  
   url: 'gericht2db.php',
  
  type: 'POST',
  
  data: 'radio_row=blablubeldiblub' ,
  
  success: function(data) {
  //Optional callback function on success
  
   }
  
  });
  
  &lt;/script&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>And the code for the form click :</p>
  
  <pre><code>require_once 'db_config.inc.php';
  require_once 'functionsgerichte.php';
  $connection = mysql_connect($db_server,$db_user,$db_password);
  mysql_select_db($db_database,$connection);
  $LetzterTag = $_REQUEST['letztertag'];
  $AlleTage = array();
  $year= $_REQUEST['jahr'];
  $month= $_REQUEST['monat'];
  for($i=0; $i&lt;$LetzterTag;$i++) { 
      //Erstellung von je einem Object je Tag
      $ActiveDay[$i] = new NeuerTag;      
      array_push($AlleTage,$ActiveDay[$i]);
  }       
  $i = 0 ;
  for($i=1; $i&lt;$LetzterTag;$i++) {
      $time = $year.'-'.$month.'-'.$i;
      if(date('l',strtotime($time)) == "Saturday" ||date('l',strtotime($time)) == "Sunday" || in_array(strtotime($time), $Freietage)) 
          $ActiveDay[$i]-&gt;Feiertag = true;
  
      if($ActiveDay[$i]-&gt;Begin == 0) {    
          $naechstesessen= $_REQUEST['naechstesessen'];
          $fleischrequest='fleisch_'.$i ;
          $fleisch= $_REQUEST[$fleischrequest];
          $veggierequest='veggie_'.$i ;
          $veggie= $_REQUEST[$veggierequest];
          $connection=mysql_connect('oris', 'root', 'orhro');
          mysql_select_db('anwesenheit',$connection);
  
          if ($naechstesessen== "radio_1") {
              $sql = "update gericht set naechstesessen='1'";         
              try {
                  $query = mysql_query($sql);
              } catch (Exception $e) {
                  echo $e-&gt;getMessage();
              }   
              $sql = "update gericht set naechstesessen='1' where Datum='".$time."'";
              try {
                  $query = mysql_query($sql);
              } catch (Exception $e) {
                  echo $e-&gt;getMessage();
              }               
          }
          $sql = "DELETE from gericht where Datum='".$time."'";
          try {
              $query = mysql_query($sql);
          } catch (Exception $e) {
              echo $e-&gt;getMessage();
          }
          $sql = "INSERT INTO gericht (Datum,Fleisch,Vegetarisch) VALUES ('".$time."','".$fleisch."','".$veggie."')";
          try {
              $query = mysql_query($sql);
          } catch (Exception $e) {
              echo $e-&gt;getMessage();
          }
      }
  }
  Header("Location: ".$_SERVER['HTTP_REFERER']."");
  </code></pre>
  
  <p>EDIT: I also want to keep the previously clicked radio button to remain active after I clicked on my form, added form to source code.</p>