douba3378 2014-02-11 12:39
浏览 23
已采纳

PHP MySQLi获取数组自动递增int失败[重复]

I currently have a table which has an int(11) called lindex.

In another table "landtb" it has an auto_increment index int(11) called index.

I've checked to see that both have the correct variable, which is 4.

the query and code involved is:

$lindex = $addressRow['lindex'];
$landQuery = \mysqli_query($connection, "SELECT * FROM landtb WHERE index='$lindex'");
$landRow = \mysqli_fetch_array($landQuery);

I've echo'd the content of $lindex and it shows the correct value also of "4", but when I run the code I get the following:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\Documents and Settings\Garry\My Documents\Dropbox\htdocs\Websites\The_Archive\propertySQL.php on line 43

If I change lindex to a string, and then also change landQuery's WHERE to looks at a name it works fine and pulls the row. So for some reason its just having issues searching with index.

I've been at it for an hour now, and I get the feeling I'm going to have done something really stupid like leaving of semi-colon in c. I don't thing it'll have any effect on the question, but I'm using netbeans.

Any help would be appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • dthp96899 2014-02-11 12:42
    关注

    index is a reserved keyword in MySQL, you have to quote it with backticks if you want to use it as a column name:

    $landQuery = \mysqli_query($connection, "SELECT * FROM landtb WHERE `index`='$lindex'");
    

    You should always check for failure of your queries:

    if (!landQuery) {
        die (mysqli_error($connection));
    }
    

    This will show the MySQL error message. It probably says that you have a syntax error near index.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?