简体   繁体   English

用php html捕获文本区域内的文本

[英]Grabbing the text within text area with php html

Hey so I am trying to grab the user input text within a textarea but it is not working out too well. 嘿,所以我试图在一个文本区域内捕获用户输入的文本,但是效果不太好。 What is happening is that we are grabbing a text (movie review) from our server and we want the user to be able to update it and then send it back to the server. 发生的事情是,我们正在从服务器中获取文本(电影评论),并且希望用户能够对其进行更新,然后将其发送回服务器。 Anyone know what we are doing wrong?? 有人知道我们在做什么错吗? We arent getting any error, it just that we are unable to grab the textarea field data. 我们无法得到任何错误,只是因为我们无法获取textarea字段数据。 We are pretty new to php and html so I am assume it is some small typeo we are overlooking. 我们是php和html的新手,所以我认为这是一些我们忽略的小型typeo。

UPDATE: Full fills here. 更新:完全填充在这里。

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

http://dl.dropbox.com/u/21443163/updateReview.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);

You mention method='POST' in your form definition (which is right), but attempt to check $_GET['textarea'] (which is wrong either way). 您在表单定义中提到method='POST' (是正确的),但是尝试检查$_GET['textarea'] (这两种方法都是错误的)。 I'd suggest fixing the latter: sending large blocks of text in URL itself is usually not great. 我建议修复后者:在URL本身中发送大量文本通常不是很好。

Don't forget to get rid of the &review=$textarea as well; 不要忘记也要摆脱&review=$textarea no need to send the content twice, in two different variables. 无需使用两个不同的变量两次发送内容。 )

Your code, with just a few minor tweaks to make it get the proper data from the form. 您的代码仅需进行一些细微的调整即可使其从表单中获取正确的数据。 The credit goes to raina77ow , though - his answer is absolutely correct. 不过,功劳归功于raina77ow-他的回答绝对正确。 I just saw that you requested some code, so here it is. 我刚刚看到您请求了一些代码,就在这里。

Also, you need to have the form tags such that the textarea is WITHIN them, otherwise it is not part of the form, and it's data does not get posted (that edit is included below). 另外,您还需要具有表单标记,以使textarea位于其中,否则,它不是表单的一部分,并且数据也不会发布(该编辑包含在下面)。

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

If you want to send large blocks of data to the database then enclose everything in a form with the method=POST name/attribute 如果要将大数据块发送到数据库,则将所有内容都用method=POST name / attribute括起来

 <form action="updatingScript.php" name="myForm" method="POST" >

     <textarea name="textArea" rows="5" cols="40"><?=$review ?></textarea>

</form>

Then in your updatingScript.php do this 然后在您的updateingScript.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);

}

Also set error_reporting(E_ALL); 还要设置error_reporting(E_ALL); at the beginning of your PHP script as this will display what went wrong (in response to your "we aren't getting any errors") 在您的PHP脚本的开头,因为这将显示出问题所在(以回应您的“我们没有收到任何错误”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM