In this article, we will explain how to create a login system in PHP using a session. ['username']!=$username && $row['password']!=$password) { $error="<p>Wrong User Name and Password</p>"; } if(isset($error)) { echo $error; } else{ require('db.php'); session_start(); $result =mysql_query("select * from users where username='$username' and password='$password'"); while($row=mysql_fetch_array($result)) { $_SESSION['username']=$row['username']; echo"<script>window.location.href='../invoice/'</script>"; } } } ?> db.php <?php mysql_connect('localhost','root',''); […]
after login, we need to fetch Username. We will explain How to Fetch Logged in Username. index.php <?php include("db.php"); session_start(); if($_SESSION['username']=="") { session_destroy(); header("location:index.php"); } ?> <html> <head> <title>Fetch Loged in Username</title> </head> </body> <?php include('db.php'); $query="select * from user where username='".$_SESSION['username']."' "; $query1=mysql_query($query); $row=mysql_fetch_array($query1) ?> <h1> <?php echo $row['name']; ?></h1> </body> </html> db.php <?php […]