php将textarea内容上传到mysql表中

发布于 2025-01-04 19:54:28 字数 972 浏览 1 评论 0原文

我有 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());

    }
?>

非常感谢。

问候。

i have html/php code with form standard desing that includes textarea item. i can't find the way to add textarea content to a table in mysql database.

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

    }
?>

thank you very much.

greetings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人疚 2025-01-11 19:54:28

也许尝试更改:

<form>

至:

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

从我所看到的内容中,没有什么真正浮现在脑海中...

您总是可以这样做:

<?php
print_r($_POST);
?>

在最顶部查看提交后页面中到底有什么内容...

Perhaps try changing:

<form>

To:

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

Nothing else really springs to mind from what I can see...

You could always do:

<?php
print_r($_POST);
?>

At the very top to see what exactly is coming into the page upon submit....

z祗昰~ 2025-01-11 19:54:28

还将您的查询行更改为此,代码中存在语法错误:

$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/ - 这肯定会在将来为您节省大量时间。

Also change your query line to this, there is a syntax error in your code:

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

Consider looking at escaping data before inserting it into the database, more information here: http://www.php.net/manual/en/book.filter.php

Edit:
Maybe you should also look at how you debug PHP: http://www.ibm.com/developerworks/library/os-debug/ - This will definitely save you a lot of time in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文