PHP
if($count == 1) {
session_register("username");
$_SESSION['username'] = $username;
header("location: ../home");
}else {
$error = "Your Login Name or Password is invalid";
}
HTML -- 第 43 行
<?php echo "<p class='text-danger'>$error</p>"; ?>
Notice: Undefined variable: error in directory on line 43
最佳答案
Error occurred because, when if statement is true then only under if statement block code would be executed not else block code. So $error variable did not initialized. Each variable should be initialized if you want to use it. $error variable did not initialize but you use it in HTML-- line 43. Thanks
$error ="";
if($count == 1) {
session_register("username");
$_SESSION['username'] = $username;
header("location: ../home");
}else {
$error = "Your Login Name or Password is invalid";
}
关于php - 尝试将变量打印到 HTML 中时 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41779216/