I have a login form in my project and i want to know the code how to show the other forms only when the login is successful. The code below is the login code.

<?php
	 extract($_POST);
	 $uname=$_POST['user'];
	 $pwd=$_POST['password'];
	$con=mysql_connect('localhost','root','')

	or

	die('could not connect:'.mysql_error());

	mysql_select_db("priya",$con);
	$result=mysql_query("select * from user 
	where user='$user' and password='$password'");

	if(($row=mysql_fetch_array($result))!=0)
	{
	 $msg="Login successfu!!!";
	}
	else
	{
	$msg="Access Denied";
	}
	echo $msg;
 
	mysql_close($con);
	
	?>

do this

<?php
extract($_POST);
$uname=$_POST['user'];
$pwd=$_POST['password'];
$con=mysql_connect('localhost','root','')
 
or
 
die('could not connect:'.mysql_error());
 
mysql_select_db("priya",$con);
$result=mysql_query("select * from user
where user='$user' and password='$password'");
 
if(($row=mysql_fetch_array($result))!=0)
{
$msg="Login successfu!!!";
header("refresh:1;url='insertphpnamehere'.php");	//that 1 means( after one second delay)
}
else
{
$msg="Access Denied";
}
echo $msg;
 
mysql_close($con);
 
?>

Surely the first thing you need to do is set your session to keep the user logged in and then you would just use an if statement to check is logged in before showing the other forms:

<?php
session_start();
	 extract($_POST);
	 $uname=$_POST['user'];
	 $pwd=$_POST['password'];
	$con=mysql_connect('localhost','root','')

	or

	die('could not connect:'.mysql_error());

	mysql_select_db("priya",$con);
	$result=mysql_query("select * from user 
	where user='$user' and password='$password'");

	if(($row=mysql_fetch_array($result))!=0)
	{
         $SESSION['user_id'] = $row['user_id'];
	 $msg="Login successfu!!!";
	}
	else
	{
	$msg="Access Denied";
	}
	echo $msg;
 
	mysql_close($con);
	
	?>
<?php if (isset($_SESSION) && !empty($_SESSION['user_id'])) { ?>
Show forms here
<?php } ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.