打印文本区域的内容不起作用


Print the content of text area not working

php:

 if(isset($_POST['submit_']))
 {
    if(isset($_POST['textEditor']) && !empty($_POST['textEditor']))
    {
       echo 'hello';
       $msg = $_POST['textEditor'];
       echo ($msg);
    }
 }

html:

 <input type="submit" name="submit_" value="Add" />
 <textarea name="textEditor" rows="20" cols="60" > </textarea>

我想在单击提交按钮时打印文本区域的内容。但是,即使文本区域不是空的,它也不会打印任何内容。

为了进行测试,我打印了"hello",但它仍然不打印任何不满足第二个"if"语句的内容我不明白为什么第二个"if"语句失败了

如果我删除第二个if语句,那么我会得到一个错误:

Notice: Undefined index: textEditor in...

你似乎有texteditor在表单之外,你需要像一样尝试

<?php
if(isset($_POST['submit_']))
 {
    if(isset($_POST['textEditor']) && !empty($_POST['textEditor']))
    {
       echo 'hello';
       $msg = $_POST['textEditor'];
       echo ($msg);
    }
 }
?>
<form method="post">
<textarea name="textEditor" rows="20" cols="60" > </textarea>
<input type="submit" name="submit_" value="Add" />
</form>

如果表单已设置,请尝试检查php代码中的表单method="post"print_r($_POST);

试试这个:

<html>
<?php
    if(isset($_POST['submit_']))
 {
    if(isset($_POST['textEditor']) && !empty($_POST['textEditor']))
    {
       echo 'hello';
       $msg = $_POST['textEditor'];
       echo ($msg);
    }
 }
?>
<head>

</head>
<body>
    <form name="myForm" method="post">
        <textarea name="textEditor" rows="20" cols="60" > </textarea>
        <input type="submit" name="submit_" value="Add" />
    </form>
</body>
</html>

希望它能帮助

可能正在调试的代码会对您有所帮助。将此代码放在if(isset($POST[提交'](下({行

echo "<pre>";
print_r($_POST);
echo "</pre>";

希望这能有所帮助。