php - MySQL 插入不起作用

标签 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());

最佳答案

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

 $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/

相关文章:

php - 如何从 Laravel 集合中获取多维关联数组的值

php - 为什么这个页面添加号码和重定向失败?

php - 自 docker 更新以来的 Symfony Autowiring 问题

php - 如何通过从我的数据库中读取值来选择单选按钮?

mysql - 用户 'User' @'%' 和 'User' @'localhost' 不一样吗?

mysql - 如何按同时具有选择和计数的字段进行分组

sql - 返回连接结果的 Postgresql 函数

php - Laravel 8,找不到模型工厂类

mysql - Django Mysql 二进制日志错误

java - OpenJPA 左外连接条件