串联声明时未定义的变量 [英] Undefined variable when declaring with concatenation

查看:84
本文介绍了串联声明时未定义的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了未定义的变量$ ar,$ pr和$ af。

I get an undefined variable $ar, $pr and $af.

$sql = mysqli_query($connection, "Select empno, username, password, access_level from personaltab where access_level='ADMIN'");

$cnt = mysqli_num_rows($sql);
$i=0;

while ($r=mysqli_fetch_array($sql)){
$md = md5($r['username']."!@#$%^&*()_+|");
$ar .= $md.", ";
$mdp = md5($r['password']."|+_)(*&^%$#@!<>?:{}[]=-");
$pr .= $mdp.", ";
$af .= $r['empno'].", ";
}


推荐答案

您需要初始化变量在循环之前。否则,将没有初始值可连接。

You need to initialize the variables before the loop. Otherwise, there's no initial value to concatenate to.

$ar = '';
$pr = '';
$af = '';
while ($r = mysqli_fetch_array($sql)) {
    ...
}

这篇关于串联声明时未定义的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆