dongyun234854 2015-06-29 22:39 采纳率: 0%
浏览 49
已采纳

php中的$ _POST数组[重复]

When I compile my code inside of my browser I get the error, "
Notice: Undefined index: firstname in C:\xampp\htdocs\index.php on line 76
"

Here is the code:

<form method="post">
<div class="form-group">
<label for="name">First Name:</label>
<input type="text" name="firstname" class="form-control" placeholder="First Name"
value="<?php echo $_POST['firstname']; ?>" />
</div>
</form>

My goal with this is to save the user's data if an error occurs after they click the submit button. Any help would be appreciated. Thank you.

</div>
  • 写回答

1条回答 默认 最新

  • douqipi9704 2015-06-29 22:43
    关注

    You only "want" to output the variable/element's value if such variable/element exists. Test it via isset() first.

    <form method="post">
        <div class="form-group">
            <label for="name">First Name:</label>
            <input type="text" name="firstname" class="form-control"
                placeholder="First Name"
                value="<?php echo isset($_POST['firstname']) ? htmlspecialchars($_POST['firstname']) : ''; ?>" 
            />
        </div>
    </form>
    

    see
    http://docs.php.net/isset
    http://php.net/language.operators.comparison#language.operators.comparison.ternary
    http://docs.php.net/htmlspecialchars

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

报告相同问题?

悬赏问题

  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗