0

alot of people told me iam using this the old way and i dont understant the newer way. can some one help me out..
iam trying to build form that will run same file.
so i have only one file called login.php
my form should run php script inside itself, when user click on button.

old way so i been told

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') 
{
}
?>
<form action='login.php' method='POST'>
    <button type="submit" id="login_button" class="button" >Log in</button> 
</form>

so i guess new way is?

<?php
    if(isset($_POST['login_button']))  
    {
    }
    ?>
    <form action='login.php' method='POST'>
        <button type="submit" id="login_button" class="button" >Log in</button> 
    </form>

but doesnt work. i also tried this but dont work:
<form action='<?php echo $_SERVER['PHP_SELF']; ?>' method='POST'>

Edited by hwoarang69

2
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by hwoarang69
4

@hwoarang69

alot of people told me iam using this the old way and i dont understant the newer way. can some one help me out..

The second way is correct. I hope that make sense.

Try this code:

<?php
if(isset($_POST['login_button'])){
$username_p = $_POST['username'];
$password_p = $_POST['password'];
$remember_p = $_POST['remember'];
}
?>
<form action='login.php' method='POST'>
<button type="submit" id="login_button" class="button" >Log in</button>
</form>

Edited by LastMitch: grammer

Votes + Comments
To Rectify what some retard did to LastMitch
0

the 2nd way is doesnt work. when i click on button it stay on login.php page. so i guess form work fine. also it prints echo"test1"; but the if statment dont work bc it never print echo"test2";

<?php
     echo"test1";
     if(isset($_POST['login_button']))  
    {
    echo"test2";
    ....
    }
?>
 <form action='login.php' method='POST'>
        <button type="submit" id="login_button" class="button" >Log in</button> 
    </form>

if i create two files. like bellow. that it works fine.
login2.php

<?php
         echo"test1";
         if(isset($_POST['login_button']))  
        {
        echo"test2";
        ....
        }
    ?>

    login.thml
    <form action='login2.php' method='POST'>
            <button type="submit" id="login_button" class="button" >Log in</button> 
        </form>

Edited by hwoarang69

2

Try this:

<?php
if(isset($_POST['login_button'])){
$username_p = $_POST['username'];
$password_p = $_POST['password'];
$remember_p = $_POST['remember'];
if (!$username_p){
echo "Username not correct";
} else if (!$password_p){
echo "Password not correctr";
} else if (!$remember_p{
echo "Don't Remember";
}
?>
<form action='login.php' method='POST'>
<button type="submit" id="login_button" class="button" >Log in</button>
</form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.