Monday, 7 March 2011
Friday, 4 March 2011
LOGIN PAGE
U need o create 3 files.
1. In Config.php file you initialize your database.(localhost/phpmyadmin)
2. In Login.php file your login script.
3. Finally in Result.php file your output result.
//name the file Config.php
<?php
$uname = 'root';
$pass = ''; //by default password is null or empty
//connection info
if (!($conn=mysql_connect($host, $uname, $pass))) {
printf("error connecting to DB by user = $uname and pwd=$pass");
exit;
}
$db=mysql_select_db($dbname,$conn) or die("Unable to connect to
database1");
?>
// Login.php file
<?php
<form action="result.php" method="post">
<body>
<label><b>LOGIN :</b></label></br>
<label style="display: block; float: left; width: 100px">NAME :</label><input type="text" name="username"/><br>
<label style="display: block; float: left; width: 100px">PASSWORD :</label><input type="password" name="password"/></br>
<input type="submit" value="LOGIN"/></br>
</body>
?>
// Result.php file
<?php
include('config.php');
$username = $_REQUEST['username'];
$password =$_REQUEST['password'];
$sql=mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'");
$row=mysql_num_rows($sql);//for checking if required username and password is correct or not
if($row>0)
{
echo "LOGIN SUCCESSFUL";
}
else
{
echo "FAILED";
}
?>
1. In Config.php file you initialize your database.(localhost/phpmyadmin)
2. In Login.php file your login script.
3. Finally in Result.php file your output result.
//name the file Config.php
<?php
$host = 'localhost';
$dbname = 'user';
$uname = 'root';
$pass = ''; //by default password is null or empty
//connection info
if (!($conn=mysql_connect($host, $uname, $pass))) {
printf("error connecting to DB by user = $uname and pwd=$pass");
exit;
}
$db=mysql_select_db($dbname,$conn) or die("Unable to connect to
database1");
?>
// Login.php file
<?php
<form action="result.php" method="post">
<body>
<label><b>LOGIN :</b></label></br>
<label style="display: block; float: left; width: 100px">NAME :</label><input type="text" name="username"/><br>
<label style="display: block; float: left; width: 100px">PASSWORD :</label><input type="password" name="password"/></br>
<input type="submit" value="LOGIN"/></br>
</body>
</form>
?>
// Result.php file
<?php
include('config.php');
$username = $_REQUEST['username'];
$password =$_REQUEST['password'];
$sql=mysql_query("SELECT * FROM user WHERE username='$username' AND password='$password'");
$row=mysql_num_rows($sql);//for checking if required username and password is correct or not
if($row>0)
{
echo "LOGIN SUCCESSFUL";
}
else
{
echo "FAILED";
}
?>
Thursday, 3 March 2011
MYSQL DATABASE
First you create database in your MYSQL from this site http://localhost/phpmyadmin
than create database name (user) for login file. .
create database tables. .login and attributes username and password.
or copy this query. .
CREATE TABLE `user`.`login` (`username` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL) ENGINE = InnoDB;
that's it. .
than create database name (user) for login file. .
create database tables. .login and attributes username and password.
or copy this query. .
CREATE TABLE `user`.`login` (`username` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL) ENGINE = InnoDB;
Insert data into table.
or copy this query. .
INSERT INTO `user`.`login` (`username`, `password`) VALUES ('test', 'test'),VALUES('username','password');that's it. .
Subscribe to:
Posts (Atom)
