dongtuo4723 2012-07-24 16:52 采纳率: 0%
浏览 441
已采纳

将变量从PHP传递给HTML

I have a page, play.html:

    <form method="post" action="play.php">
         <input type="hidden" name="mp3name" value="/MP3/1.mp3">
         <input type="submit"  value="Play My MP# #1" />
    </form>


<form method="post" action="play.php">
    <input type="hidden" name="mp3name" value="/MP3/2.mp3">
    <input type="submit"  value="Play My MP# #2" />
</form>

This calls another page, play.php:

<?php

$formurl = "play.html" ;
$playerurl = "player.html" ;

$mymp3 = $_GET["mp3name"]; 

header( "Location: $playerurl?mp3name=$mymp3" );
exit ;
?>

Then it calls another page, player.html:

<audio id="player" src="$mymp3" autoplay preload="auto"> </audio>
       <div>
       <button onclick="document.getElementById('player').play()">Play</button>
       <button onclick="document.getElementById('player').pause()">Pause</button>
       <button onclick="document.getElementById('player').volume+=0.1">Volume Up</button>
       <button onclick="document.getElementById('player').volume-=0.1">Volume Down</button>
          </div> 

How do I pass a variable from PHP to player.html?

  • 写回答

4条回答 默认 最新

  • dongni9825 2012-07-24 16:56
    关注

    You are getting the variable $mymp3 with $_GET while you are using <form method='post'.., change it to $mymp3 = $_POST['mp3name'];

    Then, change your player.html extension to player.php to use PHP code on it.

    So, when you have your player.php file, change this...

    <audio id="player" src="$mymp3" autoplay preload="auto"> </audio>
    

    to this...

    <audio id="player" src="<?php echo $mymp3 ?>" autoplay preload="auto"> </audio>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?