Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ex. html
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>Untitled Document</title>
- </head>
- <body>
- <p> </p>
- <form action="loginform.php" method="post">
- User Name:<input type="text" name="username" /><br /><p>
- Password:<input type="password" name="password" /><br /><p>
- <input type="submit" name="submit" value="Login" />
- </form>
- </body>
- </html>
- loginform.php
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
- <title>Untitled Document</title>
- </head>
- <body>
- <?php
- session_start();
- $username=$_POST['username'];
- $password=$_POST['password'];
- if ($username&&$password)
- {
- $connect = mysql_connect("localhost","root"," ");
- if(!$connect)
- { die("couldn't find database"); }
- mysql_select_db("sample");
- $query = mysql_query("select * from login where username='$username'");
- $numrows = mysql_num_rows($query);
- if($numrows!=0)
- {
- while($row = mysql_fetch_assoc($query))
- {
- $dbusername = $row['username'];
- $dbpassword = $row['password'];
- }
- if($username==$dbusername&&$password==$dbpassword)
- {
- echo 'Login successful';
- $_SESSION['username']= $dbusername;
- }
- else
- echo 'Incorrect Password';
- } //end of numows
- else
- die("That username doesnt exist");
- } // end of first if
- else
- die("Please enter username and password");
- mysql_close($connect);
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment