dourou9477 2018-03-06 18:28
浏览 57
已采纳

MySQL php查询似乎返回错误的结果(可能很明显)

MySql Appears to be returning the wrong result and I do not know why (new to mysql so its probably obvious but I couldn't find the answer)

home.php:

    $testUID = query("SELECT `uid` FROM `userid` WHERE `session_id` = '".$_COOKIE['phpAuth']."'",$link);
            echo $testUID;

echoes "1" when $_COOKIE['phpAuth'] is "ABCD"

But the MySQL userid table looks like this (test values obviously) so surely it should return 0?

    name  | pass     | csrf | uid  | session_id
    -------------------------------------------
    admin | password | ABCD | 0    | ABCD

Sorry I forgot completely that query() was my own function and ($link is the connection the the database)

function query($request,$link) {
    return mysqli_query($link,$request)or die(mysqli_error($link));
}

EDIT:

Simplified,

echo mysqli_fetch_assoc(mysqli_query(mysqli_connect("localhost", "root", "", "testdb"),"SELECT `uid` FROM `userid` WHERE `session_id` = 'ABCD'"))['uid'];

works perfectly but is in no way different to the current process as far as I can see so I'm even more confused.

echo mysqli_fetch_assoc($testuid)['uid'];

doesn't work with error

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, 
boolean given in C:\xampp\htdocs\Home.php on line 37
  • 写回答

1条回答 默认 最新

  • doubaomao9304 2018-03-06 19:16
    关注

    To anyone interested, changing

    function query($request,$link) {
        return mysqli_query($link,$request)or die(mysqli_error($link));
    }
    

    to

    function query($request,$link) {
        return mysqli_query($link,$request);// or die(mysqli_error($link));
    }
    

    resolves the error completely

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

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错