该值未插入到数据库中

发布于 2024-09-13 00:16:28 字数 1249 浏览 3 评论 0原文

我想在数据库中存储超过1000个字符,我使用MySQL数据库。

当我插入 50-100 个字符时,代码运行成功。但是当我插入1000个字符时,它就没有插入。它也不会给出错误。

当我在 phpMyAdmin 中使用类似的插入查询时,查询成功运行。 这是查询,前两个字段是 varchar &最后一个字段是 Longtext:

INSERT INTO news (headline,date,discription)
VALUES ("hi","date","A crumbling pitch and some resurgent Indian bowling have set up a gripping deciding Test with the series lead threatening to slip out of the hosts' grasp. India had snuck ahead at the end of the third day, but were dominant by lunch on the fourth as Pragyan Ojha and Amit Mishra ran through the Sri Lankan batting. Thilan Samaraweera, the centurion from the first innings, held firm and is key to Sri Lanka's fortunes as they try to build a lead that is competitive enough to give their spinners a chance. ")

这在 phpMyAdmin 中运行成功

但是当我尝试在 PHP 中运行它时,它无法运行。

这是 PHP 代码:

 $insert = "INSERT INTO news (headline,date,discription)
 VALUES ('".$_POST['headline']."','".$_POST['date5']."','".$_POST['discription']."')";
 $add_news = mysql_query($insert);

&此代码在标签中使用

<textarea rows="2" cols="2" style="overflow: scroll; height: 90px; width: 635px;" name="discription"></textarea>

I want to store more than 1000 character in database, I use MySQL database.

When I insert 50-100 characters the code runs successfully. But when I insert 1000 characters it is not inserted. It also doesn't gives an error.

When I use similar insert query in phpMyAdmin, the query runs successfully.
this is the query, first two fields are varchar & the last field is Longtext:

INSERT INTO news (headline,date,discription)
VALUES ("hi","date","A crumbling pitch and some resurgent Indian bowling have set up a gripping deciding Test with the series lead threatening to slip out of the hosts' grasp. India had snuck ahead at the end of the third day, but were dominant by lunch on the fourth as Pragyan Ojha and Amit Mishra ran through the Sri Lankan batting. Thilan Samaraweera, the centurion from the first innings, held firm and is key to Sri Lanka's fortunes as they try to build a lead that is competitive enough to give their spinners a chance. ")

This run successfully in phpMyAdmin

But when I try to run it in PHP, then it can't run.

Here is the PHP code:

 $insert = "INSERT INTO news (headline,date,discription)
 VALUES ('".$_POST['headline']."','".$_POST['date5']."','".$_POST['discription']."')";
 $add_news = mysql_query($insert);

& this code is use in tag

<textarea rows="2" cols="2" style="overflow: scroll; height: 90px; width: 635px;" name="discription"></textarea>

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

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

发布评论

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

评论(1

旧城烟雨 2024-09-20 00:16:28

在字符串变量之前使用 mysql_real_escape_string 函数,例如:

mysql_real_escape_string($_POST['discription'])

这很可能是因为文本包含单引号应该转义的。

mysql_real_escape_string — 转义
字符串中使用的特殊字符
在 SQL 语句中

您的代码应如下所示:

$headline = mysql_real_escape_string($_POST['headline']);
$description= mysql_real_escape_string($_POST['discription']);
$date= mysql_real_escape_string($_POST['date5']);

$insert = "INSERT INTO news (headline,date,discription) VALUES ('".$headline."','".$date."','".$description."')";
$add_news = mysql_query($insert) or die(mysql_error());

请注意,在末尾添加 或 die(mysql_error() ),这会告诉您查询本身是否存在任何错误。

Use the mysql_real_escape_string function before your string variables eg:

mysql_real_escape_string($_POST['discription'])

This could be most likely because the text contains single quotes which should be escaped.

mysql_real_escape_string — Escapes
special characters in a string for use
in an SQL statement

Your code should look like this:

$headline = mysql_real_escape_string($_POST['headline']);
$description= mysql_real_escape_string($_POST['discription']);
$date= mysql_real_escape_string($_POST['date5']);

$insert = "INSERT INTO news (headline,date,discription) VALUES ('".$headline."','".$date."','".$description."')";
$add_news = mysql_query($insert) or die(mysql_error());

Note that addition of or die(mysql_error() at the end, this would tell you if there is any error in the query itself.

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