- 此问题在此处已有答案**:
(29个答案)
2天前关闭。
调用while循环外的变量会出错调用变量的正确方法是什么?
$gettingusername = $_GET['username'];
global $connectionDB;
$sql = "SELECT name, lastname FROM admin WHERE username=:username";
$stmt = $connectionDB->prepare($sql);
$stmt->bindValue(':username', $gettingusername);
$stmt->execute();
$result = $stmt->rowCount();
if($result==1){
while ($fetch = $stmt->fetch()){
$existingname = $fetch['name'];
$existinglastname = $fetch['lastname'];
}
}
<html>
<?php echo $existingname;?> //OUTPUT UNDEFINED VARIABLE HOW TO FIX IT?
<?php echo $existinglastname;?> //OUTPUT UNDEFINED VARIABLE HOW TO FIX IT?
</html>
1条答案
按热度按时间atmip9wb1#
在while和if之前创建变量