Posted on 21-08-2009
Filed Under (PHP beginner) by Elfin Ruler

Login with php

Step:1 create table with mysql database
CREATE TABLE /*!32312 IF NOT EXISTS*/ `admin ` (
`admin_id` int(11) NOT NULL auto_increment,
`admin_username` varchar(50) default NULL,
`admin_password` varchar(50) default NULL,
`company_name` varchar(100) default NULL,
`address` text,
`currency` varchar(50) default NULL,
`emailid` varchar(100) default NULL,
PRIMARY KEY (`admin_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

Step- 2 Create page page (index.php)

UserName Password

Step-3 create indexsubmit.php

define("NAME","mydatabase");
define("USER",'root');
define("PASSWORD",'');
define("HOST","localhost");
$link = mysql_connect(HOST,USER,PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(NAME,$link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}

// Function that will redirect the page with given arguments.
function page_redirect($page)
{

print "";
header ("Location : $page");
}
if($_POST["SIGNIN"]!="")
{
$sql="select * from admin where admin_username='".$_POST["username"]."'";
$res=mysql_query($sql);
if(mysql_num_rows($res)>0)
{
if($row=mysql_fetch_array($res))
{
if($row["admin_password"]==$_POST["password"])
{
$_SESSION["admin_id"]=$row["admin_id"];
page_redirect("welcome.php");
}
else
{
$msg="Invalid Username and password";
}

}
else
{
$msg="Invalid Username and password";
}
}
else
{
$msg="Invalid Username and password";
}
page_redirect("index.php?msg=".$msg);

}
?>

Step-3 create welcome.php

// Function that will redirect the page with given arguments.
function page_redirect($page)
{

print "";
header ("Location : $page");
}

if($_SESSION["admin_id"]=="")
{
page_redirect("index.php");
}
Echo “login success”;
?>

(0) Comments    Read More   
BACK-LINKS and PAGE-RANK WEB DIRECTORY

Free targeted website traffic - www.ad-traffic.net