Whats wrong with this code. PHP seams fussy about executing forms in PHP. Code: These are demo's of our current songs from the past 6 months. Click <a href="comsongs.php">here</a> for a complete list of our songs. <form action="player.php" target="player" method="POST"> <?php $dirname = "songs"; $dh = opendir($dirname) or die("Couldn't open directory"); while (!(($file = readdir($dh)) === false ) ) { if (is_dir("$dirname/$file")) { } echo "<button type="submit" name="music" value=' $file '>$file</button>"; } closedir($dh); ?> </form> Ive tried putting the open and end form lines of code into the php with echo too, no dice. Any suggestions?
You can use php blocks btw PHP: These are demo's of our current songs from the past 6 months. Click <a href="comsongs.php">here</a> for a complete list of our songs. <form action="player.php" target="player" method="POST"> <?php $dirname = "songs"; $dh = opendir($dirname) or die("Couldn't open directory"); while (!(($file = readdir($dh)) === false ) ) { if (is_dir("$dirname/$file")) { } echo "<button type="submit" name="music" value=' $file '>$file</button>"; } closedir($dh); ?> </form> I think your problem is: PHP: echo "<button type="submit" name="music" value=' $file '>$file</button>"; should be PHP: echo '<button type="submit" name="music" value='.$file.'>$file</button>'; I don't have my webserver here at the moment so I can't check.
when you are echoing stuff, putting a double quotation mark effectively closes what you are outputting. use a single quote or " for quotes in echoed html so it should be PHP: echo "<button type="submit"name="music" value='$file'>$file</button>"; or PHP: echo "<button type='submit' name='music' value='$file'>$file</button>"; Nick
Close but not 100% exact. You can open using single or double quotes, but where-ever there is a matching quote to what you opened you close that point. so you can use PHP: echo "some value is ".$value." see <a href='test' />"; or equally PHP: echo 'some value is '.$value.' see <a href="test" />';
Also, using double quotes means that the string is parsed by PHP, using single quotes it's treated as plain text. PHP: echo "Today is $day"; echo 'Today is $day'; The first one would print the value of $day, the second would just print '$day'.