What's new

PHP Login program with if else (php)

SUNRAI

Eternal Poster
Joined
Feb 1, 2018
Posts
515
Reaction
59
Points
349
Age
23
IMG_20210625_091643.jpg

Pa help naman po kung anong magiging itsura neto new lang po ako sa php
 

Attachments

ito basic.. script

PHP:
if (something) {

  // member 1

} elseif(something){

 // member 2

} elseif(something){

 // member 3

} else {

 // if member 1,2,3 not found

// do something

}
 
PHP:
<?php

$username1 = "username1";
$password1 = "password1";
$username2 = "username2";
$password2 = "password2";
$username3 = "username3";
$password3 = "password3";


if (username1) {
    //first user

    echo "Authorization Accepted!";

} elseif(username2){
    //second user

    echo "Authorization Accepted!";

} elseif(username3){
    //third user

    echo "Authorization Accepted!";

} else {
    //if member 1,2,3 not found

    echo "Authorization denied!";
}

?>




<html>
    <body>
        <form method= "post">
            <input type= "user" name= 'username' />
            <input type= "password" name= 'password' />
            <input type= "submit" name= 'login' value ='login' />
        </form >
    </body>
</html>

Ok lang po ba ginagawa ko idle
 
Try mo to TS

[CODE lang="php" title="Simple login using conditional statements"]<?php

$username1 = "ben";
$password1 = "benpass";
$username2 = "tom";
$password2 = "tompass";
$username3 = "kim";
$password3 = "kimpass";

if (isset($_POST['username']) && isset($_POST['password']))
{
if ($_POST['username'] == $username1 && $_POST['password'] == $password1) {
//first user
echo "Authorization Accepted. <b>$username1</b> login successfully.";
} elseif ($_POST['username'] == $username2 && $_POST['password'] == $password2) {
//second user
echo "Authorization Accepted. <b>$username2</b> login successfully.";
} elseif ($_POST['username'] == $username3 && $_POST['password'] == $password3) {
//third user
echo "Authorization Accepted. <b>$username3</b> login successfully.";
} else {
//if member 1,2,3 not found
echo 'Authorization denied!';
}
} else {
echo 'Please enter username and password to login';
}

?>

<html>
<body>
<form name="login" action="" method="post">
<input type="text" name="username" />
<input type= "password" name="password" />
<input type= "submit" name="login" value="login" />
</form >
</body>
</html>[/CODE]
 
Last edited:

Similar threads

Back
Top