简体   繁体   English

“where 子句”中的未知列“locals_id”

[英]Unknown column 'locals_id' in 'where clause'

I'm working on a recipe page where a user clicks a recipe link and the data(full recipe) is displayed on the following page, but I can't seem to get it to work.我在一个食谱页面上工作,用户点击一个食谱链接,数据(完整食谱)显示在下一页上,但我似乎无法让它工作。 When I try to run the page I get the error "Unknown column 'locals_id' in 'where clause."当我尝试运行该页面时,出现错误“‘where 子句中的未知列‘locals_id’”。 Here is my code so far.到目前为止,这是我的代码。

?php 
    //connection variables
        $hostname = 'hostname';
        $username = 'username';
        $password = '********';
        $database = 'database';  

        //connect to the server
        $dbc = mysql_connect($hostname, $username, $password) or die("Unable to connect to mySQL server");

        //connect to the database
        mysql_select_db($database) or die("Unable to select database");


        $recipe_link = "-1";
        if (isset($_GET['locals_id'])) {
          $recipe_link = $_GET['locals_id'];
        }

        $query_recipeDetails = sprintf("SELECT * FROM recipe WHERE locals_id = %s", GetSQLValueString($recipe_link, "int"));
        $result = mysql_query($query_recipeDetails, $dbc) or die(mysql_error());
        $row_recipeDetails = mysql_fetch_assoc($result);



?>

I'm pretty new when it comes to php so I've really been tearing my hair out on this one.谈到 php 时,我还是个新手,所以我真的在这个问题上焦头烂额。 I looked through some of the other problems that were similar to mine but those didn't seem to help either.我查看了其他一些与我的问题类似的问题,但这些问题似乎也无济于事。 Any help with this would be greatly appreciated对此的任何帮助将不胜感激

Query and code seems correct.查询和代码似乎是正确的。

Check your column name carefully.仔细检查您的列名称。 there might be some typo mistake or check for case sensitivity .可能有一些typo错误或检查是否case sensitivity locals_id might be local_id locals_id可能是local_id

Check the column name is similar to "locals_id" in database tables and these are case sensitive, otherwise give column name between this symbol ` in the query.检查列名是否与数据库表中的“locals_id”相似并且区分大小写,否则在查询中在此符号 ` 之间给出列名。

eg.,例如。,

`locals_id`

Run from mysql console:从 mysql 控制台运行:

SHOW CREATE TABLE recipe;显示创建表配方;

or run或运行

SHOW FIELDS FROM recipe;从食谱中显示字段;

And you'll find out the correct names for the columns.您会找到列的正确名称。 Anyway MySQL column names are case insensitive, so you have a misstype in you script probably.无论如何 MySQL 列名称不区分大小写,因此您的脚本中可能输入错误。

Thanks for all the help everyone.谢谢各位的帮助。 I figured it out.我想到了。 It was indeed something to do with locals_id not being a column name.这确实与 locals_id 不是列名有关。 The correct name was recipe_id.正确的名称是 recipe_id。 I feel silly for not seeing it.没看到我觉得很傻。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM