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'>

Recommended Answers

All 4 Replies

Member Avatar for LastMitch

@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>
commented: 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>
Member Avatar for LastMitch

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>

o got it. in button i forgot to put

name="login_button"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.