dougou8458 2013-03-06 17:49
浏览 51
已采纳

在php中解析回声

I have an email form in php which has 3 possible appearances.

Firstly, when the submit button has not been used, I want it to appear standard.

Secondly, when submit HAS been clicked and no data was set in it.

Thirdly, when data was input acceptably, I want to display what was input.

However, I am a total php newbie and I don't seem to be able to get it right.

<?php
    if(isset(sent)) {
        if(isset($_POST['forename']) && !empty($_POST['forename']) {
            echo('<input class="tbox" type="text" name="forename" value="$POST['forename']" /><br>');
        } else {
            echo('<input class="tbox bad" type="text" name="forename" value=""/><br>');
        }
    } else {
        echo('<input class="tbox" type="text" name="forename" value="" /><br>') ;
    }
?>

I assume the error is the "s and 's. I get an unexpected ) exception. How should the echo lines be constructed to avoid this?

  • 写回答

2条回答 默认 最新

  • dsrw29618 2013-03-06 17:56
    关注

    This is your problem:

    echo('<input class="tbox" type="text" name="forename" value="$POST['forename']" /><br>');
    

    Variables don't get parsed inside single quotes, only in double quotes.

    An easy solution would be:

    echo '<input class="tbox" type="text" name="forename" value="' . htmlspecialchars($POST['forename']) . '" /><br>';
    

    Note that I have used htmlspecialchars to avoid your variable breaking the html. You also don't need to use parenthesis when you use echo (doesn't harm though...).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分