Php 该值未插入到db中

Php 该值未插入到db中,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,我想在数据库中存储1000多个字符,我使用MySQL数据库 当我插入50-100个字符时,代码将成功运行。但当我插入1000个字符时,它不会被插入。它也不会给出错误 当我在phpMyAdmin中使用类似的插入查询时,查询成功运行。 这是查询,前两个字段是varchar,最后一个字段是Longtext: INSERT INTO news (headline,date,discription) VALUES ("hi","date","A crumbling pitch and some resur

我想在数据库中存储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>

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

mysql_real_escape_string($_POST['discription'])
这很可能是因为文本包含应转义的单引号

mysql\u real\u escape\u字符串-Escapes 字符串中供使用的特殊字符 在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()
),这会告诉您查询本身是否有错误。

还要确保您在某种程度上捕捉到了错误,因为我在您的查询中看到了(斯里兰卡的)单词,如果您没有逃脱,它肯定会出错。@Pratikg88注意添加
或die(mysql_error())
最后,这会向恶意用户泄露非常敏感的信息。请使用
或trigger_error(mysql_error()。$insert)
语句,并在生产系统上关闭显示错误site@Col.弹片:我让他添加它只是为了检查查询中可能存在的问题,是的,他同意在获得生存后应该禁用它(假设)或者像你说的那样使用输出不太敏感的消息。直播后不应禁用错误跟踪。事实上,在直播站点上,可能的错误消息的重要性要高出1000倍。这就是为什么应该始终使用trigger_error()。@Col.Shrapnel:再次同意。