【问题标题】:php upload textarea content into mysql tablephp将textarea内容上传到mysql表中
【发布时间】:2012-03-04 07:28:04
【问题描述】:

我有包含 textarea 项的表单标准设计的 html/php 代码。我找不到将 textarea 内容添加到 mysql 数据库中的表的方法。

html/php

<form action="this_file.php" method="POST">
    <textarea class="inputcat" type="text" cols="40" rows="5" name="content"></textarea>
    <input type="submit" value="upload text" name="submit">
</form>
<?php
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'user', 'pass') or die(mysql_error());
$db = mysql_select_db('dbname', $con) or die(mysql_error());
    if(isset($_POST['submit'])){
        //insert the row into the database
        $contenido = $_POST['content'];
        $SQL = "INSERT INTO `table1` (`ct`) VALUE('" .$contenido. "')"; // syntax corrected here
        $result = mysql_query($SQL) or die(mysql_error());

    }
?>

非常感谢。

问候。

【问题讨论】:

  • 更正了您的语法错误...以上内容现在对您有用吗?
  • 不,不是。我会慢慢看到好多了。我会告诉你一些事情。
  • $SQL 行上的分号之前应该有另一个 " - 它在上面丢失了,我在大约一个小时前尝试编辑它,但编辑没有放在它的位置 - 我已经再试一次,但这是一个说明应该纠正的地方
  • 我不明白你的回答
  • $SQL = "INSERT INTO 'table1' ('ct') VALUE('" .$contenido. "')"; ... 另外,您是否尝试过print_r($_POST); 来查看发送的内容??

标签: php mysql textarea


【解决方案1】:

也许尝试改变:

<form>

收件人:

<form action="name_of_this_file.php" method="post">

从我所看到的内容中,没有什么真正能想到的......

你总是可以这样做的:

<?php
print_r($_POST);
?>

在最顶部查看提交时进入页面的确切内容....

【讨论】:

  • 删除了我的答案,因为这基本上回答了这个问题,而且也好一点。
【解决方案2】:

同样将你的查询行改成这样,你的代码中存在语法错误:

$SQL = "INSERT INTO `table1` (`ct`) VALUE ('$contenido')";

考虑在将数据插入数据库之前查看转义数据,更多信息在这里:http://www.php.net/manual/en/book.filter.php

编辑: 或许你也应该看看你是如何调试 PHP 的:http://www.ibm.com/developerworks/library/os-debug/——这肯定会为你以后节省很多时间。

【讨论】:

  • 是的 - 只是为了回应上述内容,请确保您清理数据输入 - 我们现在不想要任何讨厌的 SQL 注入!
猜你喜欢
  • 2015-08-15
  • 1970-01-01
  • 1970-01-01
  • 2012-11-17
  • 2015-04-12
  • 1970-01-01
  • 2017-05-16
  • 2015-05-25
  • 1970-01-01
相关资源
最近更新 更多