用textarea使用$ _POST问题 [英] Issue using $_POST with a textarea

查看:131
本文介绍了用textarea使用$ _POST问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上有一个简单的联系表单,其中包含2个文本字段,1个textarea和1个隐藏字段。



由于某些原因,一个除textarea之外的PHP脚本。我以前做过这一千次,从未有过这个问题。



这是我的HTML:

 < form action = scripts / contactform.phpmethod =post> 
< tr>
< td>名称:< / td>
< td>< input name =nametype =textmaxlength =50/>< / td>
< / tr>
< tr>
< td>电子邮件:< / td>
< td>< input name =emailtype =text/>< / td>
< / tr>
< tr>
< td>讯息:< / td>
< td>< textarea name =commentid =commentcols =30rows =5>< / textarea>
< input type =hiddenvalue =<?php echo $ _SERVER ['REMOTE_ADDR'];?> name =address/>
< / td>
< / tr>
< tr>
< td colspan =2align =center>< input name =submittype =submitvalue =Submitclass =noroundid =regbut/> < input name =resettype =resetvalue =Resetclass =noroundid =regbut/>< / td>
< / tr>
< / table>
< / form>

我的脚本如下所示:

  $ link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); 
if(!$ link)
{
die('无法连接到服务器:'。mysql_error());
}

$ db = mysql_select_db(DB_DATABASE);
if(!$ db)
{
die(无法选择数据库);
}

$ name = mysql_real_escape_string($ _ POST ['name']);
$ email = mysql_real_escape_string($ _ POST ['email']);
$ comment = mysql_real_escape_string($ _ POST ['comment']);
$ ipaddress = mysql_real_escape_string($ _ POST ['address']);

我有几件事要处理下面的数据,但这并不重要,因为 $ comment 变量未被定义。我搜索了整个脚本,并且没有相互冲突的变量名称。



我完全害怕这种情况发生的原因。我之前多次在我的网站上成功处理过 textarea 的所有内容,所以这确实令人困惑。

解决方案

我曾经遇到类似于你的错误。帮助我的是使用不同的 id name 参数。亲自尝试一下,因为在这里你有他们相同的。


I have a simple contact form on a website that has 2 text fields, 1 textarea, and 1 hidden field.

For some reason, all the fields POST to a PHP script except the textarea. I have done this a thousand times before and never had this issue.

Here is my HTML:

<form action="scripts/contactform.php" method="post">
<table width="0" border="0" cellspacing="3" cellpadding="5" class="gpass">
  <tr>
    <td>Name:</td>
    <td><input name="name" type="text" maxlength="50" /></td>
  </tr>
  <tr>
    <td>E-mail:</td>
    <td><input name="email" type="text"/></td>
  </tr>
  <tr>
    <td>Message:</td>
    <td><textarea name="comment" id="comment" cols="30" rows="5"></textarea>
    <input type="hidden" value=" <?php echo $_SERVER['REMOTE_ADDR'];?>" name="address" />
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><input name="submit" type="submit" value="Submit" class="noround" id="regbut" /><input name="reset" type="reset" value="Reset" class="noround" id="regbut"/></td>
  </tr>
</table>
</form>

And my script looks like this:

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if(!$link) 
{
    die('Failed to connect to server: ' . mysql_error());
}

$db = mysql_select_db(DB_DATABASE);
if(!$db) 
{
    die("Unable to select database");
}

$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$comment = mysql_real_escape_string($_POST['comment']);
$ipaddress = mysql_real_escape_string($_POST['address']);

I have a few things to process the data underneath this, but that doesn't matter since the $comment variable isn't being defined. I've searched the entire script and there are no conflicting variable names.

I am completely stumped on why this is happening. I've successfully processed textarea's on my site multiple times before, so this really is confusing.

解决方案

I once experienced an error similar to yours. What helped me was to use different id and name parameters. Try and see for yourself, because you have them identical here.

这篇关于用textarea使用$ _POST问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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