嘿,我的登錄腳本有問題。當我在if語句中嘗試訪問變量時,就像他們無法訪問它就像他們是私人的。我曾嘗試使用PHP $ GLOBALS使其成爲全球性的,但我沒有成功。這裏是一些示例代碼。PHP中的不可訪問變量
<?php
$error = array();
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username)){
$error[] = 'Username can not be empty'; //This will show error
}elseif(empty($password)){
$error[] = 'Password can not be empty'; //This will show error
}elseif(empty($error)){
$stmt = $pdo->prepare("SOME QUERY");
$stmt -> execute(array(':username' => $username, ':password' => $password));
$count = $stmt -> fetchColumn(0);
if($count == 1){
$stmt = $pdo->prepare("SOME QUERY");
$stmt -> execute(array(':username' => $username, ':password' => $password));
$results = $stmt->fetch(PDO::FETCH_ASSOC);
if($results['status'] == 1){
$error[] = 'you are banned'; //This will not show error
}
}
}else{
foreach($error as $alert){
$errors = '<p><b>example</b>' . $alert . '</p>';
}
}
?>
<html>
<head>
<title>Example</title>
</head>
<body>
<?php echo (!empty($errors) ? $errors : ''); ?>
</body>
</html>
這是示例代碼笑它不是我會用。 –
你太有趣了,但感謝您的反饋! –