我在我的数据库中有一个文件......数据类型是LONGTEXT
我的插入查询是:
if(isset($_POST['submit'])){
$sql='INSERT INTO `tb_mansi` (`referrence`) VALUES ("'.$_POST["legis"].'")';
if (!mysql_query($sql, $con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
}
现在,当我插入数据时,它显示的错误就像像孩子或“rena”这样的数据......意味着它给出了包含双引号的数据错误......或“'” 我试图插入这个数据
“
Indira Nehru Gandhi v. Raj Narain, AIR 1975 SC 2299;
Seshan, CEC of India v. Union of India and ors., (1995) 4 SCC 611;
Kuldip Nayar v. Union of India & Ors., AIR 2006 SC 3127;
People's Union for Civil Liberties and another v. Union of India and another, (2013) 10 SCC 1;
Mohinder Singh Gill and another v. Chief Election Commissioner, New Delhi and others, (1978) 1 SCC 405;
Raghbir Singh Gill v. S. Gurcharan Singh Tohra, AIR 1980 SC 1362;
Union of India v. Association for Democratic Reforms and another, (2002) 5 SCC 294;
Dinesh Trivedi, M.P. and others v. Union of India and others, (1997) 4 SCC 306; Anukul Chandra Pradhan, Advocate Supreme Court v. Union of India and others, (1997) 6 SCC 1;
K. Prabhakaran v. P. Jayarajan, AIR 2005 SC 688;
Niranjan Hemchandra Sashittal and another v. State of Maharashtra, (2013) 4 SCC 642;
Dr. Subramanian Swamy v. Director, Central Bureau of Investigation & Anr., Writ Petition (Civil) No. 38 of 1997 etc. pronounced on May 06, 2014;
Lily Thomas v. Union of India and others, (2013) 7 SCC 653;
His Holiness Kesavananda Bharati Sripadagalvaru v. State of Kerala and another, (1973) 4 SCC 225;
Centre for PIL and another v. Union of India and another, (2011) 4 SCC 1; N.Kannadasan v. Ajoy Khose and others, (2009) 7 SCC 1;
Inderpreet Singh Kahlon v. State of Punjab, (2006) 11 SCC 356; Arun Kumar Agarwal v. Union of India, (2014) 2 SCC 609;
State of Punjab v. Salil Sabhlok and others, (2013) 5 SCC 1 and Centre for Public Interest Litigation and another v. Union of India and another, (2005) 8 SCC 20
2; 但我得到的错误是:
错误:您的SQL语法出错;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 '0CGEQ_xc附近'style =“margin-top:0px; margin-bottom:0px; margin-left:0px;颜色:第1行的r'
任何人都可以帮助我....
答案 0 :(得分:1)
您必须使用mysql_escape_string()
来转义特殊字符
使用此代码
if(isset($_POST['submit'])){
$sql='INSERT INTO `tb_mansi` (`referrence`) VALUES ("'.mysql_escape_string($_POST["legis"]).'")';
if (!mysql_query($sql, $con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
}
注意:最好使用mysqli或pdo而不是mysql,因为从PHP 5.5开始正式弃用mysql