hey all,

I'm having some troubles with radio buttons. I'm trying to create them dynamically (which i can do without any problems) but now i'm not sure how to get the information of which button was selected. Can anyone help me? Thanks in advance:)

this is my code:

<html>
<head>
<?PHP

if (isset($_POST['Submit1'])) 
{
	for($l = 1; $l<$i;$l++)
	{
		$selected_radio = $_POST['RadioGroup1'];
		print $selected_radio;
		if ($selected_radio = $i) 
		{
			print $i;
		}
	}
}
else
{
	echo "hey";
}


?>
</head>
<body>
<Form name ="form1" Method ="Post" ACTION ="teste.php">
<?php
$mysql_host = "localhost";
$mysql_database = "gps";
$mysql_user = "root";
$mysql_passwd = "";

$conn = mysql_connect($mysql_host,$mysql_user,$mysql_passwd);

if(!$conn){
	die("Erro de ligação!");
	exit;	
}

$resultado = mysql_select_db($mysql_database,$conn);

	
if(!$resultado){
	die("Erro a obter dados!");
	exit;	
}
$result = mysql_query("SELECT * FROM lugares");
$i=1;
while($row = mysql_fetch_array($result))
{
  echo "<input type=\"radio\" name=\"RadioGroup1\" value=".$i." />".$i."<br />";	
  echo $row['Id_lugar'] . "<br /> " . $row['Ocupado'] . " <br />" . $row['Tipo'];
  echo "<br />";
  $i= $i+1;
}
for($l = 1; $l<$i;$l++)
{
		print $l;
}
?>
<P>
<Input type = "Submit" Name = "Submit1" Value = "Select a Radio Button">
</FORM>

</body>
</html>

If you will add a javascript function sel(val){} and the radio tag looks like this '<input type="radio" onchange="sel('.$i.')" name="RadioGroup1" value='.$i.' />'.$i.'<br />';
This will help in selecting the radio button. You have to choose between onclick or onchange event, it depends on what you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.