Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Button stopped submitting

I was working on my schoolproject and suddenly the form won't submit anymore. I don't remember me changing anything about it so here it is. Nothng happens when the form gets submitted and $_POST is just an empty array. if($login->isloggedin()) returns false.

<?php
include_once 'classes/loginsysteem.php';
// New object of Login class
$login = new Login;
// check is user is logged in
var_dump($login->isloggedin());
if ($login->isloggedin()) {
    header("Location: index.php");
    exit;
} else {
    if(isset($_POST['inloggen'])) {
        // username setten in Login class
        $login->setUsername($_POST['gebruikersnaam']);
        // password setten in Login class
        $login->setPassword($_POST['wachtwoord']);
        // authenticate user and create session to login
        $login->login();
        // Ga naar index pagina
        header("Location: index.php");
        exit;
    }
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>M in Events | Inloggen</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
    <div id="loginwrap">
        <form class="formulier" method="post">
            <table>
                <tr>
                    <td>
                        <h2>Inloggen</h2>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="text" name="gebruikersnaam"
                               placeholder="Gebruikersnaam" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="password" name="wachtwoord"
                               placeholder="Wachtwoord" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" class="knopje" name="inloggen" value="Inloggen" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    </body>
    </html>
<?php
}
?>

Hello!

I tested the form itself to see if it was the cause, and the form works just fine. I commented out the existing PHP code and simply added echo $_POST['gebruikersnaam']; and submitted the form.

Can you please post 'classes/loginsysteem.php'? (Make sure you remove any sensitive passwords if there are any present).

(On a crapshot, try adding 'Session_Start();' at the top of the file present in your post file.)

Thanks!

5 Answers

You do not have an action attribute in your form tag. Where is it?

It's not required.

The form needs to submit your form's information somehow...either by adding the form's action attribute or using Javascript.

EDIT: nvm

Ok...my fault, you are submitting it to the same file. You have a var_dump function at the top...maybe that is causing to fail?

Nah, i added it to see if i could find what was going wrong.

Ok let me copy and past your code on my end, and see if I can figure this out....just give me a couple of minutes. .

Could you paste your loginsysteem.php(is it actually loginsysteEn.php?) code? In order for me to instantiate a login object, I need to have that code too.