As the second stage in a dynamic customer input, I want to generate a radio button value from a database table. The table has one column only - and from a set of tables where the number of rows varies.
My attempt looks like this:
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
mysql_select_db("thedatabase") or die ("Unable to select database!");
$query = "SELECT * FROM $thetable";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
//list items in single-column table
echo '<form action="nextpage.php" method="post">';
while ($row = mysql_fetch_row($result)) {
echo '<li>';
foreach ($row as $item)
echo '<p><input type="radio" name="size" value= "$item">'.$item.'</p>' ;
echo '</li>';
}
echo '<input type="submit" name="Submit" value="Continue">';
echo '</form>';
All looks well. If the expected value of $item is 65 - then I see 65 on the screen beside my radio button.
However, when I press Continue and look at nextpage.php, tha value passed on is, literally, $item, not the expected value of $item.
For example, if nextpage.php has the following code:
$size = $_POST['size'];
echo $size;
what I see printed on the screen is $item, not 65.
So, I have obviously got the value for the radio button wrong. What should it be?