0

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);
	
	?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by simplypixie
0

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);
 
?>
0

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 } ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.