I am trying to make a PHP login page that checks weather the user entered details are in the database but it returns the following error:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SLEECT * FROM users where username = NULL AND password = NULL' at line 1 in C:\xampp\htdocs\sign\login.php:18 Stack trace: #0 C:\xampp\htdocs\sign\login.php(18): PDOStatement->execute() #1
C:\xampp\htdocs\sign\login.php(31): SignIn() #2 {main} thrown in C:\xampp\htdocs\sign\login.php on line 18
What am I doing wrong and how can I fix it?
<?php
include('connection.php');
$username =$_POST['username'];
$password = $_POST['password'];
if($username == '') {
$errmsg_arr[] = 'You must enter your Username';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'You must enter your Password';
$errflag = true;
}
function SignIn(){
global $connection;
$search = $connection->prepare("SLEECT * FROM users where username =
:username AND password = :password");
$search->bindParam(':username',$username);
$search->bindParam(':password',$password);
$result = $search->execute();
$count = $result->rowcount();
if($count> 0)
{
$_SESSION['username'] = $_POST['username'];
echo "welcom to the page ";
}
else{
echo "wron email or password";
}
}
if(isset($_POST['submit']))
{
SignIn();
}
?>
the code written in connection.php is
<?php
try{
$connection = new PDO('mysql:host=localhost;dbname=signup;charset=utf8mb4',
'root', '');
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch(PDOException $err){
echo $err->getMessage();
die();
}
?>
the HTML code written is
<html>
<body>
<form method="POST" action="login.php">
<b>Enter your username: </b><br>
<input type="text" name="username"><br>
<b>Enter your password: </b><br>
<input type="password" name ="password"><br>
<input type="submit" name="submit">
</form>
</body>
</html>