0

所以,我整天都在与这个代码作斗争。我已经尝试了很多东西,但无济于事。为此,我来到这里寻求答案。

编辑:我修复了评论中提到的一些问题。然而,问题依然存在。错误是:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near
'values where `item_id` = 'Throne' ORDER BY `timestamp` DESC LIMIT 10'
at line 1

这是我的 PHP 代码:

    include("config.php");
    include("functions.php");
                if(isset($_GET['name'])){
                    $id = mysql_real_escape_string($_GET['name']);


                        $get_rares = mysql_query("SELECT * FROM rares WHERE `name` = '".$id."'") or die(mysql_error());
    $rare = mysql_fetch_array($get_rares);
                    if(mysql_num_rows($check) == 0){
                        echo 'The rare '.$id.' doesn\'t exist!<br>';





                    }else{
                        $r = mysql_fetch_array($check);
                        $ids = $r["id"];
                        $name = $r["name"];
                        $value = $r["value"];
                        $lastedited = $r["lastedited"];
                        $catid = $r["catid"];
                        $desc = $r["desc"];
                        $image = $r["image"];
                        $big_image = $r["big_image"];
                        $release_value = $r["release_value"];
                        $releasedate = $r["releasedate"];                       
                    }
                }else{
                    echo 'No rare has been selected to view.<br><br>Click <a href="members.php">here</a> to go to the rare list.';
                }
                ?>          
                <?php $values = mysql_query("SELECT * FROM values where `item_id` = '".$id."' ORDER BY timestamp DESC LIMIT 10") or die(mysql_error());
4

5 回答 5

0

省略“where”之一:

 "SELECT * FROM rares where WHERE name = ".$id.""
 //                   ***********

和:

在任何查询中,有许多词不能被视为列、表、视图或任何名称,而没有采取预防措施让 mysql 正确解释它们,看这里

values并且name是其中的两个。

于 2013-06-30T15:11:08.197 回答
0

name是一个字符串,你需要引用它。

$get_rares = mysql_query("SELECT * FROM rares WHERE name = '$id'") or die(mysql_error());

$values = mysql_query("SELECT * FROM values WHERE item_id = '$id' ORDER BY timestamp DESC LIMIT 10") or die(mysql_error());

WHERE正如@Axel 指出的那样,还写了两次。

于 2013-06-30T15:11:27.777 回答
0

在 MySQL 中,VALUESis 是一个关键字,如果不将其放在引号中,就不能将其用作字段名或表名:

SELECT * FROM values where `item_id` = '".$id."' ORDER BY timestamp DESC LIMIT 10

应该

SELECT * FROM `values` where `item_id` = '".$id."' ORDER BY `timestamp` DESC LIMIT 10
于 2013-06-30T15:21:34.927 回答
0

VALUES是 MySQL 关键字,用作名称时需要放在反引号中:

SELECT * FROM `values` WHERE `item_id` = '$id' ORDER BY timestamp DESC LIMIT 10
于 2013-06-30T15:22:29.227 回答
0

VALUES是 mysql 保留关键字,你需要用这样的反引号括起来

     SELECT * FROM `values` where

mysql保留关键字

于 2013-06-30T15:54:13.123 回答