I am trying to make a sign-in, on my website (index.php):
I made a form and sent the information to validation-sign-in.php file to make the validation:
(I will add the encryption later on)
here is the form:
<div class="sign-in-up">
<div id="sign-in-modal" class="modal">
<form method="post" class="modal-content animate" action="php/validation-sign-in.php">
<div class="imgcontainer">
<span onclick="document.getElementById('sign-in-modal').style.display='none'" class="close" title="Close Modal">×</span>
<img src="images/avatar.png" alt="Avatar" class="avatar" style="width:100px;height:100px">
</div>
<div class="container-sign-in-up">
<label><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="UserName" required>
<label><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="Password" required>
<button type="submit">Sign In</button>
<input
type="button"
id="sign-up-btn"
onclick="document.getElementById('sign-up-modal').style.display='block';
document.getElementById('sign-in-modal').style.display='none'"
value="Sign Up">
<input type="checkbox" checked="checked"> Remember me
</div>
<div class="container-sign-in-up" style="background-color:#f1f1f1">
<button type="button" onclick="document.getElementById('sign-in-modal').style.display='none'" class="cancelbtn">Cancel</button>
<span class="psw">Forgot <a href="#">password?</a></span>
</div>
</form>
</div>
</div>
and here is the validation-sign-in.php:
<?php
if(empty($_POST)){
header('location:../index.php');
}
$con=mysqli_connect("localhost","root","","typing_club");
$user = $_POST['UserName'];
$pass = $_POST['Password'];
$query = "SELECT * FROM Users WHERE " . "UserName = '".$user."' AND Password='". $pass."'" ;
echo "$query";
$result = mysqli_query($con,$query);
if (mysqli_num_rows($result) == 1) {
echo "query successfull wrote to DB";
header('location:../index.php?validation=true');
} else {
echo"unscccessful login";
header('location:../index.php?validation=false');
}
?>
Every thing is working great.
but I need to get the username and the id of the signed in user, this is to keep track of the user, to update his progress, and write his name on the web ....