如何将textarea数据发送到另一个页面?

Ver*_*cas 2 html post

我对这类事情不熟悉......我需要将3个文本区域的数据提交到另一个页面......
我该怎么做?
PS如果可以的话我会使用输入.

Fil*_*tic 8

您需要使用表单创建页面...例如,将其命名为form.html使用此代码,例如:

  <form id="form1" name="form1" method="post" action="acceptpage.php">
  <input type="text" name="input" id="textfield" />
  <textarea name="text" id="textarea" cols="45" rows="5"></textarea>
  <input type="submit" name="button" id="button" value="Send" />
  </form>
Run Code Online (Sandbox Code Playgroud)

之后创建名为acceptpage.php的页面将其放在body标签之间

<?php
$frominput = $_POST[input]; // Variable who accept your data from input
$fromtextarea = $_POST[text]; // Variable who accept your data from textarea
// You don't need to use variables, but if you starter, easier to understand.
    // Do something with your arrived data... 
// Stupid, but for short explanation... for example echo it...
echo $fromtextarea;
echo $frominput;
?>
Run Code Online (Sandbox Code Playgroud)

当然,您可以使用html发送数据,但是您无法接受数据,因为接受数据需要像php这样的编程语言.我用上面的php向你展示它是如何工作的......

编辑...(我刚才看到你想把数据放到数据库中)......这是代码:

<?php
$frominput = mysql_real_escape_string($_POST[input]);
$fromtextarea = mysql_real_escape_string($_POST[text]);
// Do something with your arrived data... 
$query = mysql_query("INSERT INTO table (rowforinput, rowfortextarea) VALUES
    ('$frominput','$fromtextarea')") or die (mysql_error());
?>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,对接受数据的变量进行的修改很少,我称之为mysql_real_escape_string函数,以使数据更安全.如果您想了解更多关于mysql_real_escape_string函数的信息,请访问mysql_real_escape_string

不要忘记首先建立与数据库的连接.为此,我通常会自己创作:

        function connect_db() {
        mysql_connect("localhost", "username", "password");
        mysql_select_db("database");
                      }
Run Code Online (Sandbox Code Playgroud)

并调用函数 <?php connect_db(); ?>

更新03.15.2015

自2011年以来在PHP中发生了很多变化.函数mysql_connect将来会被弃用.请改用mysqli或PDO.

参考:

不推荐使用mysql_connect

MySQL改进扩展(Mysqli)

PHP数据对象接口(PDO)