在输入框中输入数据时,如何在PHP中执行SQL注入?

在输入框中输入数据时,如何在PHP中执行SQL注入?,php,mysql,sql-injection,Php,Mysql,Sql Injection,如何在插入查询或选择查询的上下文中执行SQL注入?如果有任何帮助,我们将不胜感激。首先,不要使用mysql,请使用mysqli 第二,这是因为不能在mysql\u query()中放置两个查询。否则他们会将其命名为mysql\u querys() 只需提出两个不同的问题。这是我的建议 以下是手册中关于其使用的基本示例: <?php $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); /* check

如何在插入查询或选择查询的上下文中执行SQL注入?如果有任何帮助,我们将不胜感激。

首先,不要使用mysql,请使用mysqli

第二,这是因为不能在
mysql\u query()
中放置两个查询。否则他们会将其命名为
mysql\u querys()

只需提出两个不同的问题。这是我的建议

以下是手册中关于其使用的基本示例:

<?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

第二,这是因为不能在
mysql\u query()
中放置两个查询。否则他们会将其命名为
mysql\u querys()

只需提出两个不同的问题。这是我的建议

以下是手册中关于其使用的基本示例:

<?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();

为什么要允许SQL注入?结合下面的答案,您将能够执行该查询。你也可以用这个和你的数据库说再见。为什么你想允许SQL注入?好吧,结合下面的答案,你将能够执行这个查询。你也可以用这个和数据库说再见。你的意思是不要使用
mysql\u*
mysqli\u*
对吗?@Script47当然。但我认为这是可以理解的。嗯,我之所以建议它是为了清楚起见,也是为了将来可能不知道的读者。@Script47你是对的。我编辑答案是为了使用一个英文参考,你的意思是不要使用
mysql\u*
和使用
mysqli\u*
对吗?@Script47当然。但我认为这是可以理解的。呃,我之所以建议它是为了清楚起见,也是为了将来可能不知道的读者。@Script47你是对的。我编辑答案是为了使用英文参考