尝试发布文本区域值时获取空字符串


Getting empty string when trying to post textarea value

我试图通过文本区域发布文本,但我遇到了一个问题,我的问题是文本区域在弹出窗口内,当我提交表单时,会得到空字符串,因此我不能只插入文本区域值,其他在弹出窗口外的输入没有问题。

HTML:

<form action="index.php" method="post">
<!-- here are some input texts -->
<input type="text">.........
<!-- but here is a button, when click it show this popup which is written below -->
<input type="button" onclick="showPopup()">
<!-- popup -->
<div id="overlay"></div>
<div id="popup">
<textarea name="txt"></textarea> 
<input id="hidepopup" onclick="hidePopup()" type="button" value="Hide popup">
</div>
<input type="submit" name="submit" value="Submit Form">
</form>

PHP:

if(isset($_POST["submit"])
{
    $textarea = $_POST["txt"];
    $query = "INSERT INTO table ";
    $query .= "(text, other inputss....) VALUES("'$textarea', other inputs...")";
    $result = mysql_query($con, $query);
    if($result) {
       echo $textarea; // here I get empty string :(
    }
}

您没有名称为"submit"的输入,因此

if(isset($_POST["submit"]) { ... }

你永远不会在这种情况下去。

这应该有效:

<input type="submit" name="submit" value="Submit Form">

<input type="hidden" name="submit" value="1"> //this goes somewhere in the form