php中的$ _POST数组

时间:2015-06-29 22:39:37

标签: php html forms web

当我在浏览器中编译代码时,我收到错误,"
注意:未定义的索引: C:\ xampp \ htdocs \ index中的firstname .php 76 <&#34;

以下是代码:

sort

我的目标是在用户点击提交按钮后发生错误时保存用户的数据。任何帮助,将不胜感激。谢谢。

1 个答案:

答案 0 :(得分:0)

你只是&#34;想要&#34;如果存在这样的变量/元素,则输出变量/元素的值。首先通过isset()测试它。

<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>


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