Monday 3 March 2014

PHP TUTORIALS-Create Login Page with DataBase-PhpMyAdmin-Mysql

PHP TUTORIALS Create Login Page with DataBase-PhpMyAdmin-Mysql

FULL DETAILS..

PHP TUTORIALS-Create Login Page with Database using PhpMyAdmin-Mysql


PHP TUTORIALS Create Login Page with DataBase PhpMyAdmin Mysql PART2 



Program Name :- htmllogin.html

<html>

<head>

<body bgcolor="">

<font>

<center><h1>Login</h1></center>

</font>

<form action="login.php" method="POST">

Username:<input type="text" name="uname">

Password:<input type="password" name="pass"><br>

<input type="submit" value="login" name="submit">

</form>

</body>

</head>

</html>


Program Name:-  login.php

<?php

require ('sql_connect.php');

if (isset($_POST['submit'])){

$username=mysql_escape_string($_POST['uname']);

$password=mysql_escape_string($_POST['pass']);

if (!$_POST['uname'] | !$_POST['pass'])

 {

echo ("<SCRIPT LANGUAGE='JavaScript'>

        window.alert('You did not complete all of the required fields')

        window.location.href='htmlogin.html'

        </SCRIPT>");

exit();

     }

$sql= mysql_query("SELECT * FROM `login_users` WHERE `username` = '$username' AND `password` = '$password'");

if(mysql_num_rows($sql) > 0)

{

echo ("<SCRIPT LANGUAGE='JavaScript'>

        window.alert('Login Succesfully!.')

        window.location.href='htmllogin.html'

        </SCRIPT>");

exit();

}

else{

echo ("<SCRIPT LANGUAGE='JavaScript'>

        window.alert('Wrong username password combination.Please re-enter.')

        window.location.href='htmllogin.html'

        </SCRIPT>");

exit();

}

}

else{

}

?>


Program Name:-   sql_connect.php

<?php

mysql_connect("localhost", "root", "") or die("mysql connection is failure.");

mysql_select_db("login") or die("Database does not exists.");

?>

10 comments:

  1. How do you get it to redirect based on who logs in after you get the message "you've successfully logged in?"

    ReplyDelete
  2. when i give login it shows mysql connection is failure ..what may be the problem?

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I have one error in login.php if statement

    ReplyDelete
  5. I have one error in login.php if statement

    ReplyDelete
  6. when i hit the login it shows up the code in login.php.. pls help me

    ReplyDelete
    Replies
    1. first run server(xampp or wamp) than open html file by localhost like this localhost/htmllogin.html

      Delete
  7. when i loginit shows error Database does not exists.

    ReplyDelete
  8. When I open the html file (localhost/login.html) it says Object not found! What am I going to do? :(

    ReplyDelete