Im using a foreach loop as follows
Birthday: <select name="bday">
foreach ($months as $value) {
<option value="$value">$value</option>
}
</select>
the page says $value is undefined and the select box is empty. Any ideas?
where are your opening and closing <?php ... ?> tags?
What u mean, the code is within the tags, within the <body>
I tried this
$days = range(1, 31);
print '<select name="bday2">';
foreach($days as $value) {
print "<option value="/$value/">$value</option>";
print '</select>';
It works but the select box has no data in them when i click it.
Did you cut and past your code? If so then one problem is that you need backslashes and not forward slashes.
echo "<option value=\"$value\">$value</option>\n";
Yea your right, thanks. You know why the slashes are even needed, furthermore being backslashes? Thanks
Well, strings with variables need to be enclosed by double quotes. Just the way PHP was designed. So the question becomes: how to echo a double quote since normally a double quote would indicate the end of a string. The answer is to stick a back slash in front of it. This in turn causes the parser to include the double quote as part of the string and continue on.
K thanks for the clear up 🙂