Development PHP Help

Discussion in 'Software' started by crazydeep74, 3 Sep 2006.

  1. crazydeep74

    crazydeep74 What's a Dremel?

    Joined:
    25 Jul 2005
    Posts:
    762
    Likes Received:
    0
    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?
     
  2. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33
    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.
     
  3. Nedsbeds

    Nedsbeds Badger, Slime, Weasel!!

    Joined:
    16 May 2002
    Posts:
    1,972
    Likes Received:
    9
    when you are echoing stuff, putting a double quotation mark effectively closes what you are outputting. use a single quote or &quot; for quotes in echoed html

    so it should be

    PHP:
    echo "<button type=&quot;submit&quot;name=&quot;music&quot; value='$file'>$file</button>";
    or
    PHP:
    echo "<button type='submit' name='music' value='$file'>$file</button>";
    Nick
     
  4. DougEdey

    DougEdey I pwn all your storage

    Joined:
    5 Jul 2005
    Posts:
    13,933
    Likes Received:
    33

    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" />';
     
  5. eek

    eek CAMRA ***.

    Joined:
    23 Jan 2002
    Posts:
    1,600
    Likes Received:
    14
    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'.
     
  6. [Jonny]

    [Jonny] What's a Dremel?

    Joined:
    1 Sep 2003
    Posts:
    296
    Likes Received:
    0
    PHP:
    echo "<button type=\"submit\" name=\"music\" value=\"" $file "\"'>" $file "</button>";
     

Share This Page