问题
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