Just wondering if someone can give me some insight to understand how the hidden type works on a form.

This form has 3 types of controls for storing the value of $id a radio button, check box and a hidden input(which has a button for each loop also). When it loops through the correct value is stored and returned in the radio button and the checkbox.

However when I click on the button that comes after the hidden $id it is always the number of the last record whether it is the 1st or last button pressed. I always assumed that the value of the button would be the hidden value.

I have googled but noting really super comes back, anyone know of any good articles that go indepth into the hidden value when looping through database searches or can shed some light on it.

function dispayRoomsForDelete()
{
	global $link;
	global $select;
	global $page;
	$sql = "SELECT id, room_num FROM main
			ORDER BY room_num";
	$result = mysql_query($sql, $link);
	echo "<strong><u>Select room to delete</u> </strong>";
	echo "<form action=\"",$page,"\" method=\"post\" >";
	echo '<table border="1" cellspacing="0" cellpadding="0" width="150px"><br />';
			while($row = mysql_fetch_assoc($result))
			{
				echo '<tr><td align="center" width="60px">';
					$id = $row['id'];
					echo "<input type=\"radio\" name=\"deleteRoomRadio\" value=\"" ,$id, "\" />";
					echo "r " ,$id," ";
				echo '</td>';
				echo '<td align="center" width="60px">';
					echo $row['room_num'];
				echo '</td>';
				echo '<td width="30px">';	
					echo "c " ,$id,"";
					echo "<input type=\"checkbox\" name=\"check\" value=\"",$id,"\"/>";
				echo '</td>';
				echo '<td width="30px">';	
					echo "<input type=\"hidden\" name=\"deleteRoomButton\" value=\"" ,$id, "\" />";
					echo "b " ,$id,"";
					echo '<input type="submit" value="Delete"/>';
				echo '</td></tr>';
			}
	echo '<table>';	
	echo "</form>";
}

solved once I stopped and thought, form element needs to be inside the loop, creating new form each loop.

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.