用php-html抓取文本区域中的文本


Grabbing the text within text area with php html

嘿,所以我试图在文本区域中获取用户输入的文本,但效果不太好。现在的情况是,我们正在从服务器上获取文本(电影评论),我们希望用户能够更新它,然后将其发送回服务器。有人知道我们做错了什么吗??我们没有得到任何错误,只是我们无法获取文本区域字段数据。我们对php和html还很陌生,所以我认为这是我们忽略的一些小类型。

更新:此处填写完整。

http://dl.dropbox.com/u/21443163/Reviews.php

http://dl.dropbox.com/u/21443163/updateReview.php

while($RecordSetMovieRow = odbc_fetch_array($RecordSetMovie))
        {
            echo "<tr>";
                $review = $RecordSetMovieRow['Review'];
                echo "<td align = 'center'>" . $RecordSetMovieRow['FirstName']. $RecordSetMovieRow['LastName']  . "</td>";
                echo "<td align = 'center'><textarea name = 'textarea' rows = '5' cols= '40'>" . $review . "</textarea></td>";
                $textarea = $_GET['textarea'];
                $u = $Re[0];
                echo "<td><form action = 'updateReview.php?id=".$RecordSetMovieRow['ReviewID']."&review=$textarea' method = 'POST'><input type='submit' value='Update'></form></td>";
            echo "</tr>";
        }
        echo "</table>";
        odbc_close($Conn);

如果要将大块数据发送到数据库,请使用method=POST名称/属性将所有数据封装在一个表单中

 <form action="updatingScript.php" name="myForm" method="POST" >
     <textarea name="textArea" rows="5" cols="40"><?=$review ?></textarea>
</form>

然后在您的更新脚本.php中执行此

 if(isset($_POST['myForm'])) {
    $textInfo = mysql_real_escape_string($_POST['textArea']);
    //move this info in your database
    mysql_connect("localhost", "root", "");
    mysql_select_db("myDb")  
    $query="UPDATE myTable SET userTextInfo='$textInfo' WHERE userId='$userId' "; 
    $result=mysql_query($query);
}

还可以在PHP脚本的开头设置error_reporting(E_ALL);,因为这将显示出了什么问题(作为对"我们没有得到任何错误"的回应)

您在表单定义中提到了method='POST'(这是正确的),但尝试检查$_GET['textarea'](无论哪种方式都是错误的)。我建议解决后者:在URL中发送大块文本通常不太好。

别忘了去掉&review=$textarea;不需要在两个不同的变量中发送两次内容。)

您的代码,只需进行一些小的调整,就可以从表单中获得正确的数据。不过,这要归功于raina77ow,他的答案是绝对正确的。我刚刚看到你要求一些代码,所以它在这里。

此外,您需要有表单标记,以便文本区域在其中,否则它不是表单的一部分,并且它的数据不会被发布(下面包括编辑)。

echo '<form action = 'updateReview.php?id=".$RecordSetMovieRow['ReviewID']."' method = 'POST'>'; // Moved this outside of the while - BUT it needs to be BEFORE the <table> tag also!
echo '<table>'; // If this is not where you want your opening table tag, that's fine - but move the opening FORM tag to BEFORE the opening Table tag
while($RecordSetMovieRow = odbc_fetch_array($RecordSetMovie))
    {
        echo "<tr>";
            $review = $RecordSetMovieRow['Review'];
            echo "<td align = 'center'>" . $RecordSetMovieRow['FirstName']. $RecordSetMovieRow['LastName']  . "</td>";
            echo "<td align = 'center'><textarea name = 'textarea' rows = '5' cols= '40'>" . $review . "</textarea></td>";
            $textarea = $_POST['textarea']; // Changed from $_GET["textarea"] because you are using method='post' in form
            $u = $Re[0];
            echo "<td><input type='submit' value='Update'></td>";
        echo "</tr>";
    }
    echo "</table>";
echo '</form>'; // Moved this to the end of the form, so data from form will get passed
    odbc_close($Conn);