I want to create a login page in php using PDO and I have created this class which includes the function login which makes the login.
<? php
class Utente {
private $db;
function __construct($conn) {
$this - > db = $conn;
}
public static
function login($nome_utente, $password) {
$nome_utente = $_POST['nome_utente'];
$password = $_POST['password'];
if ($nome_utente == '') {
echo "Fill the name";
}
try {
$stmt = $this - > db - > prepare("SELECT * FROM utente WHERE nome_utente = :nome_utente AND password=:password");
$stmt - > execute();
$utenteRow = $stmt - > fetch(PDO::FETCH_NUM);
if ($utenteRow > 0) {
echo "You are logged in";
} else echo "The username doesnt match with the password!";
} catch (PDOException $e) {
echo $e - > getMessage();
}
}
}?>
<!-- begin snippet: js hide: false console: true babel: false -->
<form action="" method="POST">
Name
<input type="text" name="nome_utente" />PAS
<input type="text" name="password" />
<input type="submit" name="submit" value="login" />
</form>
Now I want to call this function to see the result of the login.I create this new class in another php file to call it:
<?php
class Call
{
public function call()
{
$var=Utente::login();
return $var;
}
}
?>
The problem is when I execute the secon file with the class Call I see a blank page. Have I done something wrong? Can someone tell me how to do the login of the user in the right way? Thanks!