Thursday, 12 September 2013

get the option chosen from a form in html and assign it to php variable

get the option chosen from a form in html and assign it to php variable

I need to collect the option chosen from a form in html and use it to
increment a value in a mysql database. The idea is: chose your name (from
the html form, already populated by mysql) chose name of your opponent
(from the html form, already populated by mysql) click submit to:
increment one victory to you and increment one defeat to your opponent.
I have the following code:
echo '<select name="tabela">';
while ($row = mysql_fetch_array($result))
{
echo "<option value='" . $row['Nome'] . "'>" . $row['Nome'] . "</option>";
}
echo '</select>';
echo $teste=$_POST['tabela'];
if ($teste=='Filipe')
{
$sql="UPDATE Jogadores SET Vitorias=Vitorias+1 WHERE Nome='Filipe'";
mysql_select_db('aventino');
$retval = mysql_query( $sql, $conn );
}
It populates the html form but I can't get 1) the name that is there by
default 2) the name that the user chooses. I have been trying lots of
solutions and nothing seems to exist in order to know and extract which
option is chosen, before clicking submit button!
Many thanks F

No comments:

Post a Comment