该值未插入到数据库中
我想在数据库中存储超过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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在字符串变量之前使用
mysql_real_escape_string
函数,例如:这很可能是因为文本包含单引号应该转义的。
您的代码应如下所示:
请注意,在末尾添加
或 die(mysql_error()
),这会告诉您查询本身是否存在任何错误。Use the
mysql_real_escape_string
function before your string variables eg:This could be most likely because the text contains single quotes which should be escaped.
Your code should look like this:
Note that addition of
or die(mysql_error()
at the end, this would tell you if there is any error in the query itself.