Login with Email or Contact using php mysql | Php Advanced

index.php file

<form action = "login.php" method = "POST">
 Email or Contact : <input type = "text" name = "user">
 Password : <input type = "password" name = "password">
 <input type = "submit" value = "Login">
</form>

login.php file

<?php
session_start();
$conn = mysql_connect("localhost","root","");
mysql_select_db("yourdatabase name",$conn);

$user = $_POST['user'];
$password = $_POST['password'];

$sql = mysql_query("select * from user where (email = '$user' or contact = '$user') and password = '$password'");
$result = mysql_fetch_array($sql);

$dbemail = $result['email'];
$dbcontact = $result['contact'];
$dbid = $result['id'];

if($user==$dbemail || $user==$dbcontact)
{
$_SESSION['id']=$dbid;
?>
<script>
    window.location='home.php';
    </script>
<?php

}


?>

home.php file

<h1>Welcome! You are loggedin now</h1>
<a href = "logout.php">Logout</a>

logout.php file

<?php
session_start();
session_destroy();
?>
<script>
    alert("You are logging out now..");
    window.location='index.php';
    </script>



Explore Our YouTube Tutorials

Dive into our YouTube tutorials to access high-quality learning content on web development, design, and technology. Each video is crafted to provide clear guidance and hands-on knowledge for skill development.

 


Upgrade Your Skills with Our Courses

Choose the right course and start building your future with practical skills.

Web Development

Learn HTML, CSS, JavaScript, and PHP to build modern, responsive websites and real-world projects.

Enroll Now See Full Details

Breadboard Learning

Understand electronics basics with hands-on breadboard projects and circuit building techniques.

Enroll Now See Full Details

AI Training

Step into AI with real-world applications, automation tools, and smart development techniques.

Enroll Now See Full Details