0

这意味着从 URL 获取数据并将其提交到数据库,它会给出错误:查询为空;

我在那里放了一些东西来测试,是的,它给出了我设置的变量的值。提前致谢

<?php
require 'variables.php';
if(empty($_REQUEST['Key']) || empty($_REQUEST['Computer']) || empty($_REQUEST['Panel'])){
die("Nothing was given for me to give back :(");
}else{
$key = $_REQUEST['Key'];
$computer = $_REQUEST['Computer'];
$panel = $_REQUEST['Panel'];
$insertquery = mysql_query("INSERT INTO keys (Key, PC, Panel) VALUES ('".$key."', '".$computer."', '".$panel."')");
$sql = mysql_query($insertquery);
if($sql){
    echo "good ". mysql_error();
}else{
    echo "bad ". mysql_error();
    echo "<br />".$key." ".$computer." ".$panel."";
}
}

?>
4

6 回答 6

0

这可能是数据库连接的问题,您正在使用 mysql_query 两次,这是不必要的。就保留关键字而言,尝试将它们写成

$insertquery = mysql_query("INSERT INTO keys (`Key`, `PC`, `Panel`) VALUES ('".$key."', '".$computer."', '".$panel."')");
于 2013-09-21T15:07:50.820 回答
0

你打mysql_query()了两次电话。那就是问题所在

这样做

<?php
require 'variables.php';
if(empty($_REQUEST['Key']) || empty($_REQUEST['Computer']) || empty($_REQUEST['Panel'])){
die("Nothing was given for me to give back :(");
}else{
$key = $_REQUEST['Key'];
$computer = $_REQUEST['Computer'];
$panel = $_REQUEST['Panel'];
$insertquery = "INSERT INTO keys (Key, PC, Panel) VALUES ('".$key."', '".$computer."', '".$panel."')";
$sql = mysql_query($insertquery);
if($sql){
    echo "good ". mysql_error();
}else{
    echo "bad ". mysql_error();
    echo "<br />".$key." ".$computer." ".$panel."";
}
}

?>
于 2013-09-21T13:14:11.420 回答
0

1.您的查询包含两个保留字keykeys您需要用反引号 (`) 将它们括起来:

INSERT INTO `keys` (`Key`, PC, Panel)

您可以通过更改列名来避免这种情况。

2. 易受SQL注入攻击,改用PDO或MySQLi,使用参数化查询。

于 2013-09-21T13:15:05.147 回答
0

key是 mysql 敏感字(保留字)。-阅读更多

您也两次调用 mysql_query 。您的 SQL 查询应如下所示:

mysql_query("INSERT INTO keys (`Key`, `PC`, `Panel`) VALUES ('".$key."', '".$computer."', '".$panel."')");

这应该会奏效。

于 2013-09-21T13:15:28.183 回答
0

问题在于这段代码:

$insertquery = mysql_query("INSERT INTO keys (Key, PC, Panel) VALUES ('".$key."', '".$computer."', '".$panel."')");
$sql = mysql_query($insertquery);

您正在传递mysql_queryinto的结果mysql_query。您应该将其更改为:

$sql = mysql_query("INSERT INTO `keys` (`Key`, PC, Panel) VALUES ('$key', '$computer', '$panel')");

顺便说一句,您需要转义数据(SQL 注入..)并使用新的 API 进行数据库连接(MySQLi/PDO)。

于 2013-09-21T13:15:35.980 回答
0

正确的代码

    <?php
    require 'variables.php';
    if(empty($_REQUEST['Key']) || empty($_REQUEST['Computer']) || empty($_REQUEST['Panel'])){
    die("Nothing was given for me to give back :(");
    }else{
    $key = $_REQUEST['Key'];
    $computer = $_REQUEST['Computer'];
    $panel = $_REQUEST['Panel'];
    $insertquery = ("INSERT INTO keys (Key, PC, Panel) VALUES ('".$key."', '".$computer."', '".$panel."')");
    $sql = mysql_query($insertquery);
    if($sql){
        echo "good ". mysql_error();
    }else{
        echo "bad ". mysql_error();
        echo "<br />".$key." ".$computer." ".$panel."";
    }
    }

?>
于 2013-09-21T13:17:35.467 回答