My login script
<?php
require 'database.php';
if(!empty($_POST['username'] ) && !empty($_POST['password'])):
$records= $conn->prepare("SELECT id,username,password FROM table2 WHERE username = ':username'");
$records->bindparam(':username', $_POST['username']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
if(count($results) > 0 && password_verify($_POST['password'], $results['password'])){
die( "sucess");
header:("login.php");
} else{ die("dieees");
}
endif;
?>
<!Doctype html>
<meta charset="utf-8">
my signup script
<?php
$server = 'localhost';
$username= 'root';
$password = '';
$database = 'users';
try{
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
} catch(PDOException $e){
die("connection failed:" .$e->getmessage());
}
if(!empty($_POST["username"]) && !empty($_POST["password"])):
$sql = "INSERT INTO table2 (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username',$_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT) );
if( $stmt->execute() ):
header:("login.php");
else:
die('fail');
endif;
endif;
?>
<html>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Supermercado+One" rel="stylesheet">
<body>
<h1> ReGiSTER</h1>
<form action="signup.php" method="POST">
<input type=text" placeholder="enter ur username" name="username">
<input type="password" placeholder=password name="password">
<input type="password" name="confirm_password">
<input type="submit">
</form>
</body>
</html>
What I have tried:
i have tried different codes these days but seem i need too give up
Always a error message or just plain not getting a login
but signup works pretty ok but giving a error on same line with hash password.