How to echo selected parameters from a question loop with php

I have this loop that answers questions from the database to the form with predefined answers in the selection options, for example, "Yes", "No", "Not sure." The user can answer any question, except that you need to answer at least one question. How to perform an echo request and the corresponding selected response to the user when submitting the form.

Here I get questions from dbase

<form method="post" action="">
<?php         
    $sql = 'SELECT starttime, country,league, home, away,gamecode 
    FROM games 
    WHERE starttime > DATE_FORMAT(NOW(),"%d/%m/%y %H:%i") 
    ORDER BY starttime' ;
    $retval = mysql_query($sql);
    if(! $retval )
    {
      die('Could not get games for the date selected: ' . mysql_error());
    }

    while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
    {

Here I return the question to the user

 echo "{$row['country']} | {$row['league']} | Time:{$row['starttime']}  <br> ". 
  "<div align='center'><span class='style3'>{$row['home']} VS ".
         "{$row['away']} <br> ".

Here I echo predetermines the selected answers for each of the above questions

EDITED // My form head is somewhere above the sql query

     "<select name='gm" . $row['gamecode'] ."' >
         <option value=''>Select option</option>
    <option value='btsyes'>BTS (YES)</option>
    <option value='btsno'>BTS (NO)</option>
    <option value='over2.5'>Over2.5(Total Goals)</option>
    <option value='under2.5'>Under 2.5(Total Goals)</option>
    <option value='oddtg'>Odd(Total Goals)</option>
    <option value='eventg'>Even(Total Goals)</option>
    </select></span></div>".
             "<hr>";
    } 

?>



 <input type="submit" name="play" value="Register Bet" />
    </form></div>

All of the above works fine, but here I want to repeat the question and answer selected back to the user to confirm

that's what i am trying

 if (isset($_POST ['play'])){
echo "Confirm Your Selection </br>";
foreach ($_POST as $key => $value ) {
  if($value !=''){   

      echo $key."-".$value;
           echo "<br>";
     }else{ echo "No valid selection Made <br>";}
    }
}

, , . , , . . 1 2

+4
1
<select name= 'gm[]'>
         <option value='so'>select option</option>
<option value='btsyes'>BTS (YES)</option>
<option value='btsno'>BTS (NO)</option>
<option value='over2.5'>Over2.5(Total Goals)</option>
<option value='under2.5'>Under 2.5(Total Goals)</option>
<option value='oddtg'>Odd(Total Goals)</option>
<option value='eventg'>Even(Total Goals)</option>
</select>

gm [], , . , , $_POST ['gm']

, , . , , , value != ''

<select name="gm"><option value=''>Choose your Answer</option></select>

'' , .

№ 2

<form action="" method="POST">

<select name='gm[firstQuestion]'>
    <option value=''>Select Please</option>
    <option value='Foo'>Foo</option>
    <option value='Bar'>Bar</option>
    <option value='Zoo'>Zoo</option>
    <option vlaue='Park'>Park</option>
</select>
<br>
<select name='gm[secondQuestion]'>
    <option value=''>Select Please</option>
    <option value='Foo'>Foo</option>
    <option value='Bar'>Bar</option>
    <option value='Zoo'>Zoo</option>
    <option vlaue='Park'>Park</option>
</select>
<br>
<select name='gm[thidQuestion]'>
    <option value=''>Select Please</option>
    <option value='Foo'>Foo</option>
    <option value='Bar'>Bar</option>
    <option value='Zoo'>Zoo</option>
    <option vlaue='Park'>Park</option>
</select>
<br>
<input type="submit" value="answer">

PHP-

foreach($_POST['gm'] as $key => $answer){
    if($answer != ''){
        echo "your Question #" . $key . ' Answer is ' . $answer . PHP_EOL;
    }

}

+2

All Articles