【问题标题】:How to perform SQL injection in PHP while inputting the data in input box? [duplicate]在输入框中输入数据时如何在 PHP 中执行 SQL 注入? [复制]
【发布时间】:2018-03-07 15:14:27
【问题描述】:

Insert querySelect query上下文中如何执行SQL Injection?任何帮助将不胜感激。

【问题讨论】:

标签: php mysql sql-injection


【解决方案1】:

首先,不要使用mysql_,使用mysqli_

其次,这是因为您不能在mysql_query() 中放置两个查询。否则他们会把它命名为mysql_queries()

只需进行两个单独的查询。这是docs

这是手册中有关其用法的基本示例:

<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

/* Create table doesn't return a resultset */
if ($mysqli->query("CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = $mysqli->query("SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", $result->num_rows);

    /* free result set */
    $result->close();
}

/* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) {

    /* Note, that we can't execute any functions which interact with the
       server until result set was closed. All calls will return an
       'out of sync' error */
    if (!$mysqli->query("SET @a:='this will not work'")) {
        printf("Error: %s\n", $mysqli->error);
    }
    $result->close();
}

$mysqli->close();

【讨论】:

  • 你的意思是不要使用mysql_*而使用mysqli_*对吗?
  • @Script47 当然。但我认为它已经被理解了。
  • 嗯,我是为了清楚起见和可能不知道的未来读者而建议的。
  • @Script47 你是对的。
  • 我编辑了答案以便使用英文参考php.net/manual/en/mysqli.query.php
猜你喜欢
  • 2011-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-01
  • 2017-10-13
  • 2020-01-04
相关资源
最近更新 更多