如何发送textarea数据到另一个页面? [英] How do I send textarea data to another page?

查看:185
本文介绍了如何发送textarea数据到另一个页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这类事情很陌生......我需要将3个文本区域的数据提交到另一个页面......

我该如何做?

PS如果可以的话,我会使用输入。

解决方案

您需要使用form创建页面...例如,调用它

 < form id =form1name =form1form.html 
使用此代码: method =postaction =acceptpage.php>
< input type =textname =inputid =textfield/>
< textarea name =textid =textareacols =45rows =5>< / textarea>
< input type =submitname =buttonid =buttonvalue =Send/>
< / form>

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

 <?php 
$ frominput = $ _POST [input]; //从输入接受数据的变量
$ fromtextarea = $ _POST [text]; //从textarea接受你的数据的变量
//你不需要使用变量,但是如果你是初学者,更容易理解。
//对你的数据做些什么...
//很笨,但是对于简单的解释...例如echo它...
echo $ fromtextarea;
echo $ frominput;
?>

当然,您可以使用html发送数据,但您无法接受数据,接受数据你需要一种像php这样的编程语言。我使用上面的php来告诉你它是如何工作的......



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

 <?php 
$ frominput = mysql_real_escape_string($ _ POST [输入]);
$ fromtextarea = mysql_real_escape_string($ _ POST [text]);
//对你的数据做些什么...
$ query = mysql_query(INSERT INTO table(rowforinput,rowfortextarea)VALUES $ b $'('from fromput','$ fromtextarea') )或死(mysql_error());
?>

正如您所看到的,接受数据的变量几乎没有修改,我称之为mysql_real_escape_string函数,使数据更安全。如果您想了解有关mysql_real_escape_string函数的更多信息,请 mysql_real_escape_string

不要忘记首先连接到数据库。为此,我通常会创建自己的函数:
$ b $ pre $ 函数connect_db(){
mysql_connect(localhost,username ,密码);
mysql_select_db(database);
}

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



UPDATE 03.15.2015

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



参考:

mysql_connect已弃用

MySQL Improved Extension(Mysqli)

PHP数据对象接口(PDO)


I am new to this kind of things... I need to submit the data in 3 text areas to another page...
How do I do that?
P.S. I would have used inputs, if I could.

解决方案

You need to create your page with form... For example call it form.html use this code for example:

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

After that create page called acceptpage.php Put this in between body tags

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

Of course, you can send data with html, but you can't accept data, for accepting data you need a programming language like php. I use php above to show you how it works...

Edit...(I just now saw that you want to you put the data into the database)... Here is code:

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

As you can see, there are little modifications at variables which accept data, I called mysql_real_escape_string function, to make data more secure. If you want to learn more about mysql_real_escape_string function, mysql_real_escape_string

Don't forget that first you make a connection to the database. For it I usually make my own function:

        function connect_db() {
        mysql_connect("localhost", "username", "password");
        mysql_select_db("database");
                      }

And call function with <?php connect_db(); ?>

UPDATE 03.15.2015

A lot of changes since 2011 in PHP. Function mysql_connect will be deprecated in future. Use mysqli or PDO instead.

Reference:

mysql_connect deprecated

MySQL Improved Extension (Mysqli)

PHP Data Objects Interface (PDO)

这篇关于如何发送textarea数据到另一个页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆