douan0729 2015-09-05 19:01
浏览 16

mysqli_real_string_escape失败了GET

I have a static database connection established in a file which I include as

include_once 'database.inc.php';

named $mysqli.

When I pass a parameter $tbname from a form using $tbname = $_GET['tbname'], and attempt to use $tbname = $mysqli->real_esacpe_string($tbname), it produces identical output to $tbname, including when invalid characters such as /,'" are used in the name.

Based on looking at other questions and proper usage, I cannot find a reason why the string escape should fail. It also fails if a procedural call is used to mysqli_real_escape_string($mysqli, $tbname).

When $tbname is valid and not string escaped by the function, my query

query = $mysqli->prepare("CREATE TABLE $tbname (ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY)") or trigger_error($mysqli->error."[$query]");

works as intended.

  • 写回答

1条回答 默认 最新

  • dssu33392 2015-09-05 19:11
    关注
    1. There is no reason to use this function for escaping a table name, and you should never use it for such a purpose.
    2. There is no reason in creating tables from user input, and you should never create tables on the fly, but always have solid and predefined database structure.
    3. mysqli_real_escape_string DOES escape these symbols \'". But you should never use it. Instead, you have to use prepared statements
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)