MySQL插入不起作用

时间:2014-06-16 21:10:51

标签: php mysql sql

我想在mysql数据库中插入数据。当我尝试使用PHP MyAdmin插入我的查询然后工作但是如果我从提交中插入从我的php网站插入不工作一些文本不插入。

我的文字

http://www.lexisnexis.com/hottopics/gacode/

§16-11-125.1。定义

如本部分所用,术语:

我的表单提交仅插入此文本

http://www.lexisnexis.com/hottopics/gacode/

我的查询

$test='http://www.lexisnexis.com/hottopics/gacode/

§ 16-11-125.1.  Definitions 

   As used in this part, the term:';
$conn = mysql_connect('localhost', 'test', 'test') or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
mysql_query('SET NAMES utf8');
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET SESSION collation_connection ='utf8_unicode_ci'");

$queryc = "INSERT INTO `table` (data17)values ('".addslashes($test)."')";
mysql_query($queryc) or die(mysql_error());

1 个答案:

答案 0 :(得分:0)

对于数据库连接,它应该是:

 $conn = mysqli_connect('localhost', 'test', 'test') or die(mysqli_error($conn));

对于查询,它应该是:

mysqli_query($conn, $queryc) or die(mysqli_error($conn);

记住,mysqli_query的参数是数据库连接,查询 另外,如果查询($ queryc)是:

,那会更好
$queryc = "INSERT INTO `table` (data17)values mysqli_real_escape_string($test))";