0
I’m trying to run this php code, but it reports me an error "Notice: Undefined variable: num_row in C: wamp64 www balance login.php on line 63" The variable was created on line 23 but it still reports the undefined error, thanks in advance!
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<title> Saldo</title>
</head>
<?php
if(isset($_POST['entrar']))
{
$username = trim($_POST['login']);
$password = trim($_POST['senha']);
$query = "SELECT login, senha FROM usuarios WHERE login='$_POST[login]'AND senha='$_POST[senha]'";
$result = mysqli_query($conn,$query) or die(mysqli_error());
$num_row = mysqli_num_rows($result);
$row=mysqli_fetch_array($result);
if( $num_row == 1 )
{
$_SESSION['id']=$row['id'];
header("Location: home.php");
exit;
}
elseif ($num_row == 0){
}
}
?>
<body>
<body>
<div class="container">
<div class="row">
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
<div class="card card-signin my-5">
<div class="card-body">
<h5 class="card-title text-center">Entrar</h5>
<form class="form-signin" method="POST" action="login.php">
<div class="form-label-group">
<input type="email" name="login" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputEmail">Email</label>
</div>
<div class="form-label-group">
<input type="password" name="senha" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="inputPassword">Senha</label>
</div>
<div class="custom-control custom-checkbox mb-3">
<input type="checkbox" class="custom-control-input" id="customCheck1">
<label class="custom-control-label" for="customCheck1">Lembrar minha senha</label>
</div>
<button name="entrar" class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Continuar</button>
<?php
if ($num_row == false){
echo "<p align = 'center'><font color ='red'> Senha incorreta </font></p>";
}
?>
<hr class="my-4">
<button class="btn btn-lg btn-secondary btn-block text-uppercase" type="submit"><i class="fab mr-2"></i> Não possui cadastro? Cadastre-se</button>
<button class="btn btn-lg btn-secondary btn-block text-uppercase" type="submit"><i class=" mr-2"></i> Esqueci minha senha</button>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</body>
</html>
But line 23 is inside a
if
. And when the condition of thisif
is not satisfied?– Woss