Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 21-Jan-18 3:41am
Comments
ThilinaMD 21-Jan-18 8:05am    
please post some debug code. eg error message

We can't tell - it's far, far too dependant on your data, and we don't have any access to that.
What you need to do is us a debugger to find out exactly what is going on while your code is running, and look at exactly what data is getting processed.
Some of this may help you get started: php debugger - Google Search[^]
Sorry, but we can't do that for you!
 
Share this answer
 
v2
i have no solution but i used var_dump();
and googled debugging. haha its so complicated though
Im rookie. but i was able to narrow it down for now to
login script and how to unhash password after hash it during signup
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900