我想在 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());
最佳答案
对于数据库连接,应该是:
$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))";
关于php - MySQL 插入不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24252262/