0

So i have a file with PHP and HTML in it. The HTML works fine but when i enter the PHP it does not render anything for some reason. See code for beter refrence. Also logs don't really say anything about the issue.

This fails to do anything

<?php

echo $_POST['naam'];
die();

?>

<!DOCTYPE html>
<html>
<head>
    <title>Scouts Permeke</title>
    <link rel="stylesheet" type="text/css" href="siteStyle.css">
</head>
<body>
    <H2>Login</H2>

    <form action="login.php" method="POST">
        <input name="naam" type="text" id="naam" class="form-control" placeholder="Gebruikersnaam"/><br>
        <input name="psw" type="password" id="psw" class="form-control" placeholder="Passwoord"/><br>
        <button type="submit">Login</button>
    </form>	
</body>
</html>

But this shows my HTML as intended.

<!DOCTYPE html>
<html>
<head>
    <title>Scouts Permeke</title>
    <link rel="stylesheet" type="text/css" href="siteStyle.css">
</head>
<body>
    <H2>Login</H2>

    <form action="login.php" method="POST">
        <input name="naam" type="text" id="naam" class="form-control" placeholder="Gebruikersnaam"/><br>
        <input name="psw" type="password" id="psw" class="form-control" placeholder="Passwoord"/><br>
        <button type="submit">Login</button>
    </form>	
</body>
</html>

5
  • Is the file extension .html or .php ? Commented Oct 5, 2016 at 17:11
  • if there is no POST variable called naam you will get an error and a blank screen - what are you seeing? Commented Oct 5, 2016 at 17:12
  • 4
    It doesn't render anything because you have echo $_POST['naam'] (which is probably null) and die() immediately after (so the code will stop running). Commented Oct 5, 2016 at 17:12
  • die, die, die! Wait, why did you stop working? Commented Oct 5, 2016 at 17:13
  • Can you give me the output off var_dump($_POST); Commented Oct 5, 2016 at 17:18

2 Answers 2

1

You need to check if the variable is actually set, otherwise it will always print out the content of $_POST['naam'] without bothering if the user already inputted data and pressed the Submit-button.

if(isset($_POST['naam'])) {
  echo $_POST['naam'];
  die();
}
Sign up to request clarification or add additional context in comments.

Comments

0

That is because it is ignoring an error as the $_POST array doesn't have the "naam" variable and your php.ini for display error is off. In php, if the array doesn't contain the key it will throw error and in this the error is ignored because of the production settings. Also, this is the reason why the "die();" line is not interpreted. Please check if php.ini has or commented

display_errors: Off

and make it into

display_errors: On

Restart apache to getting the settings work.

You can also remove/comment the first line of code in PHP tag and see if die() is working. Please do let us know if this fixed your error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.