Undefined variable when declaring with concatenation [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-12 01:53:50

问题


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'].", ";
}

回答1:


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)) {
    ...
}


来源:https://stackoverflow.com/questions/29359427/undefined-variable-when-declaring-with-concatenation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!