2014-06-05 67 views
0

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> 

我想打印時,點擊提交按鈕文本區域的內容。但即使textarea非空,它也不會打印任何內容。

對於測試,我打印'你好',但它仍然打印什麼都不是第二'如果'陳述不滿意我不明白爲什麼第二個'if'陳述失敗

如果我刪除第二個if語句,然後我得到一個錯誤:

Notice: Undefined index: textEditor in... 
+0

好像你的textarea的形式之外?爲什麼會在提交按鈕後?也許你也關閉了真實頁面上的按鈕後的表單。 –

+0

請從 –

回答

1

看來你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> 

如果形式設置已經嘗試檢查表格method="post"print_r($_POST);在php代碼

0

可能是調試代碼將幫助你。 作爲把這個代碼下如果(isset($ POST [ '提交'])){線

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

希望這會有所幫助。

1

試試這個:

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

希望它可以幫助

+0

顯示您的完整html代碼謝謝!它的作品,我已經投了票! :) –