使用串联声明时未定义的变量

时间:2015-03-31 02:08:04

标签: php string concatenation undefined

我得到一个未定义的变量$ ar,$ pr和$ 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 个答案:

答案 0 :(得分:0)

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

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