php - PDO SQL 使用 " 和 ' 输入文本字段
问题描述
尝试同时使用 " 和 ' 进行插入查询
我有$description = addslashes($description);
但我仍然得到:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以了解在 '27"","Product 附近使用的正确语法
$description
在"Capacity:26\",27\" and 700C Wheel Sizes"
之后addslashes()
。
询问:
$handler->query('INSERT INTO `tm_products`
(`title`, `description`, `member_name`, `category_path`)
VALUES ("'.$apiGetListing['Title'].'",
"'.$description.'","'.$member_name.'",
"'.$apiGetListing['CategoryPath'].'")');
我认为它试图在26\"
“?
解决方案
你真的需要清理你的论点。您对 SQL 注入持开放态度。
<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";
$conn = new mysqli($servername, $username, $password, $dbname);
$stmt = $conn->prepare("INSERT INTO tm_products(title, description, member_name, category_path) VALUES(?, ?, ?, ?))");
$stmt->bind_param("ssss", $title, $description, $member_name, $category_path);
$title= $apiGetListing['Title'];
$description= $description;
$member_name= $member_name;
$category_path = $apiGetListing['CategoryPath'];
$stmt->execute();
$stmt->close();
$conn->close();
推荐阅读
- kubernetes - 从本地机器在远程 Kubernetes 集群上部署创建的 Helm 图表
- javascript - 如何读取和修复 * 未初始化 * 变量的控制台消息
- python - h5py文件和pickle文件保存模型的区别
- java - 使用三元运算符抛出已检查或未检查的异常
- java - System.loadLibrary() 在某些情况下不起作用
- node.js - 如何在不超时的情况下使用 Express 和 Node 启动后台进程?
- database - 不使用 _id 字段在 mongodb 中查找文档的最快方法
- python - Pandas 新列从几列的 groupby 返回 max 的查找
- javascript - 关闭甜蜜警报弹出窗口并通过 AJAX 启动另一个甜蜜警报弹出窗口时出现问题
- incredibuild - Incredibuild 仅在本地构建