duancong2965 2017-06-12 01:06
浏览 48
已采纳

警告:非法字符串偏移PHP Mysqli

i'm trying to fetch data from mysql database using this code :

$con = mysqli_connect('localhost', 'root', '', 'nicu');
    mysqli_query($con, "set NAMES utf8");
    $query = mysqli_query($con, "select * from user");
    while($rows = mysqli_fetch_assoc($query)) :
        $rows = $rows["nicuAddress"];
        $address = $rows["nicuEmail"];
        echo "$rows<br>$address";
    endwhile;

but every time i run this code i get this warning :Warning: Illegal string offset

what changes do i have to do to fix this ?

  • 写回答

1条回答 默认 最新

  • dtx9931 2017-06-12 01:08
    关注

    You are trying to reaches a part of the array that was overwritten. After running $rows = $rows["nicuAddress"] you cannot access $address = $rows["nicuEmail"] as an array.

    Solution

    $address = $rows["nicuAddress"]; // <-- Change to address
    $email = $rows["nicuEmail"]; // <-- Change to email
    echo "$address<br>$email";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料