Jump to content

Need help with login


Ratee

Recommended Posts

i have a login script but i would like to make it in to 2 files like... login.html and do-login.php

i want the login form on 1 page then when you try and login it goes to.. do-login.php tp check if the information is correct

below is the code.. could someone please help me.. thanks.

 

 

<?php

session_start();

include "./global.php";

 

echo "<title>Login</title>\n";

 

if ($_SESSION['uid']) {

    echo "You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here</a>!\n";

} else {

 

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

        echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";

        echo "<form id=\"login-form\" method=\"post\" action=\"./login.php\">\n";

        echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n";

        echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n";

        echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Login\"></td></tr>\n";

        echo "</form></table>\n";

    }else {

        $user = mss($_POST['username']);

        $pass = $_POST['password'];

       

            if($user && $pass){

                $sql = "SELECT id FROM `users` WHERE `username`='".$user."'";

                $res = mysql_query($sql) or die(mysql_error());

                if(mysql_num_rows($res) > 0){

                    $sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".md5($pass)."'";

                    $res2 = mysql_query($sql2) or die(mysql_error());

                    if(mysql_num_rows($res2) > 0){

                        $row = mysql_fetch_assoc($res2);

                        $_SESSION['uid'] = $row['id'];

                       

                        echo "You have successfully logged in as " . $user . "<br><br><a href=\"./index.php\">Proceed to the Forum Index</a>\n";

                    }else {

                        echo "Username and password combination are incorrect!\n";

                    }

                }else {

                    echo "The username you supplied does not exist!\n";

                }

            }else {

                echo "You must supply both the username and password field!\n";

            }

    }

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/244363-need-help-with-login/
Share on other sites

one file will be html..

<html>
<head>
<body>
<table border="0" cellspacing="3" cellpadding="3">
        <form id="login-form" method="post" action="login.php">
        <tr><td>Username</td><td><input type="text" name="username"></td></tr>
        <tr><td>Password</td><td><input type="password" name="password"></td></tr>
        <tr><td colspan="2" align="right"><input type="submit" name="submit" value="Login"></td></tr>
        </form></table>
</body>
</head>
</html>

then in this case, login.php will contain the necessary php to handle the form..

php will be something like

 

if ($_SESSION['uid']) {
    echo "You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here</a>!\n";
} else {

    if (!$_POST['submit']) {
        $user = mss($_POST['username']);
        $pass = $_POST['password'];
        
            if($user && $pass){
                $sql = "SELECT id FROM `users` WHERE `username`='".$user."'";
                $res = mysql_query($sql) or die(mysql_error());
                if(mysql_num_rows($res) > 0){
                    $sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".md5($pass)."'";
                    $res2 = mysql_query($sql2) or die(mysql_error());
                    if(mysql_num_rows($res2) > 0){
                        $row = mysql_fetch_assoc($res2);
                        $_SESSION['uid'] = $row['id'];
                        
                        echo "You have successfully logged in as " . $user . "<br><br><a href=\"./index.php\">Proceed to the Forum Index</a>\n";
                    }else {
                        echo "Username and password combination are incorrect!\n";
                    }
                }else {
                    echo "The username you supplied does not exist!\n";
                }
            }else {
                echo "You must supply both the username and password field!\n";
            }
    }

}

when i use this code it says... "You must supply both the username and password field!" even when the login information is correct? anyone know why?

 

 

 

 

 

 

 

<?php

if ($_SESSION['uid']) {

    echo "You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here</a>!\n";

} else {

 

if (isset($_POST['submit'])) { //exclamation removed

if($user && $pass){

$sql = "SELECT id FROM `users` WHERE `username`='".$user."'";

$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) > 0) {

$sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".md5($pass)."'";

                    $res2 = mysql_query($sql2) or die(mysql_error());

                    if(mysql_num_rows($res2) > 0){

                          $row = mysql_fetch_assoc($res2);

                        $_SESSION['uid'] = $row['id'];

                       

                        echo "You have successfully logged in as " . $user . "<br><br><a href=\"./index.php\">Proceed to the Forum Index</a>\n";

                    }else {

                        echo "Username and password combination are incorrect!\n";

                    }

                }else{

                    echo "The username you supplied does not exist!\n";

                }

            }else {

                echo "You must supply both the username and password field!\n";

            }

    }

 

}

 

?>

i give up now all i wanted to do was modify what the login looked like but i cannot add div id's e.c.t to add style to it:/ because i just got errors.  this is the original code....

 

 

<?php

session_start();

include "./global.php";

 

echo "<title>Login</title>\n";

 

if ($_SESSION['uid']) {

    echo "You are already logged in, if you wish to log out, please <a href=\"./logout.php\">click here</a>!\n";

} else {

 

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

        echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\">\n";

        echo "<form id=\"login-form\" method=\"post\" action=\"./login.php\">\n";

        echo "<tr><td>Username</td><td><input type=\"text\" name=\"username\"></td></tr>\n";

        echo "<tr><td>Password</td><td><input type=\"password\" name=\"password\"></td></tr>\n";

        echo "<tr><td colspan=\"2\" align=\"right\"><input type=\"submit\" name=\"submit\" value=\"Login\"></td></tr>\n";

        echo "</form></table>\n";

    }else {

        $user = mss($_POST['username']);

        $pass = $_POST['password'];

       

            if($user && $pass){

                $sql = "SELECT id FROM `users` WHERE `username`='".$user."'";

                $res = mysql_query($sql) or die(mysql_error());

                if(mysql_num_rows($res) > 0){

                    $sql2 = "SELECT id FROM `users` WHERE `username`='".$user."' AND `password`='".md5($pass)."'";

                    $res2 = mysql_query($sql2) or die(mysql_error());

                    if(mysql_num_rows($res2) > 0){

                        $row = mysql_fetch_assoc($res2);

                        $_SESSION['uid'] = $row['id'];

                       

                        echo "You have successfully logged in as " . $user . "<br><br><a href=\"./index.php\">Proceed to the Forum Index</a>\n";

                    }else {

                        echo "Username and password combination are incorrect!\n";

                    }

                }else {

                    echo "The username you supplied does not exist!\n";

                }

            }else {

                echo "You must supply both the username and password field!\n";

            }

    }

 

}

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.