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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器