dongta5621 2011-12-15 05:04
浏览 29
已采纳

PHP按钮无法正常显示

I have a for loop displaying XML data from the last.fm API. Im wanting to add a button to each individual result from the query, however It is simply appearing as a piece of text and not recognized as a button.

$xmlmusic = new SimpleXMLElement($result); 

$releases = $xmlmusic->xpath('artist/similar/artist'); 
foreach ($releases as $artist) { 
$artistResult .= '<div class="searchitem">';
$artistName = $artist->name . PHP_EOL;
$artistResult .= $artist->name . PHP_EOL;
$artistResult .= '<form name="favourite" action="'.$_SERVER['PHP_SELF'];'" ."   method="POST">';
$artistResult .= '<input type="submit" id="graphic" value="favourite">add</form>'; 
$artistResult .= '</div>';

<?php echo $artistResult ?>

This is displaying as a small box with "add" however it isn't being seen as a button.

Link to page: Artist Search

Any help is appreciated,

JB

  • 写回答

1条回答 默认 最新

  • dougupang0901 2011-12-15 05:08
    关注

    The first issue is in this line:

    $artistResult .= '<form name="favourite" action="'.$_SERVER['PHP_SELF'];'" ."   method="POST">';
    

    You are mixing and matching quotes. Try:

    $artistResult .= '<form name="favourite" action="' . $_SERVER['PHP_SELF'] . '"' . ' method="POST">';
    

    Or better:

    $artistResult .= sprintf('<form name="favourite" action="%s" method="POST">', $_SERVER['PHP_SELF']);
    

    Or even better, just remove the action attribute as an empty action means by default to submit to the same URL.

    Your second issue is that you are creating many submit buttons all with the same ID. HTML requires that ID attributes are unique-- you cannot use the same ID on multiple elements.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染