PHP $_POST 错误 请帮助我 我正在学习 PHP

标签 php html mysql post undefined-index

我正在学习 PHP。这是源代码。

<?php
$text = $_POST['text'];

echo $text;
?>

<form action="index.php" method="post">
<input type="text" name="text" />
    <input type="submit">
</form>

这是结果。我不知道问题出在哪里。

注意: undefined index :C:\xampp\htdocs\faisal\index.php 中第 2 行的文本

最佳答案

这意味着 $_POST['text'] 中没有任何内容——并且在提交表单之前之后不会有任何内容。您需要使用 isset() 来检查:

<?php
if(isset($_POST['text'])) {
    $text = $_POST['text'];

    echo $text;
}
?>

<form action="index.php" method="post">
<input type="text" name="text" />
    <input type="submit">
</form>

关于PHP $_POST 错误 请帮助我 我正在学习 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21686380/

相关文章:

html - 在 flash 上覆盖部分 div

html - 我们如何在不使用绝对值的情况下使一列的宽度是另一列的两倍?

php - 根据 IP 地址处理在线用户 - mysql 数据库

mysql - Eloquent 查询不使用索引

php - 如何在 Zend Framework 查询中放置

php - 即使在 Head 标签之间链接之后,CSS 也不会反射(reflect)到 php 页面

java - 服务器拒绝了一个请求,但接受了另一请求。为什么?

javascript - 将秒实时转换为小时和分钟

javascript - 这个javascript和php代码有什么问题吗?

php - 查询生成器 : IN clause with composite columns