dongwen2162
2014-09-28 05:57 阅读 44
已采纳

Php用表格切换:逻辑错误?

I can't get my head around why this code doesn't keep toggling. What should be changed?

print_r( $_POST );
$direction = isset( $_POST['direction'] ) ? $_POST['direction'] : 'DESC';
$opposite = $direction == 'DESC' ? 'ASC' : 'DESC';
echo '
    <form method="POST" >
        <input type="submit" value="' . $opposite . ' " name="direction">
    </form>
';
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dsfh40613182 dsfh40613182 2014-09-28 06:02

    The culprit is:

    <input type="submit" value="' . $opposite . ' " name="direction">
                                                ^^
    

    Notice how you've got an extra space at the end of the value, value="' . $opposite . ' "

    Try changing it to:

    echo '
        <form method="POST" >
            <input type="submit" value="' . $opposite . '" name="direction">
        </form>
    ';
    
    点赞 评论 复制链接分享

相关推荐