Welcome Friends, In This Blog You Will Learn That How Can You Creat A Signup And Login Form For Your Website.
► Coding For Login Form ◄
<?php
session_start();
if(isset($_SESSION['uname']))
{
header("LOCATION:welcome.php");
exit();
}
else
{
}
// fixed
?>
<br><br>
<h1 align="center"> Welcome To Login Form </h1>
<form method="post" action="" align="center">
Email : <br><input type="text" name="email" placeholder="Enter Your Email"><br><br>
Password :<br> <input type="password" name="password" placeholder="Enter Your Password"><br><br>
<input type="submit" value="Login" name="login">
</form>
<?php
$con = mysqli_connect('localhost','root','','learn'); // database connection successfull.. ok
if(isset($_POST['login']))
{
$email = $_POST['email'];
$password = $_POST['password'];
//letst make the query
$query = "SELECT * FROM `users` WHERE `email`='$email' AND `password`='$password'";
$run = mysqli_query($con,$query);
$row = mysqli_num_rows($run);
if ($row <1 )
{
echo "<script>alert('Username Or Password Wrong')</script>".mysqli_error($con);
}
else
{
$data = mysqli_fetch_assoc($run);
$uname = $data['name'];
$_SESSION['uname'] = $uname;
header("LOCATION:welcome.php");
}
}
?>
<br>
<div align="center">
No comments:
Post a Comment