Christoffer Alexander Christoffer Alexander - 1 month ago 10
HTML Question

php html Why isn't my form showing on the webpage?

I simply cannot understand how and why I am not seeing a form, when opening my site??? I wan a form consisting of bot username, password and a subit box to appear, though I don't see the solution here...

A solution and explaining would be much appreciated.

Kind regards
Chris

<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
?>
<!DOCTYPE html>
<!--

-->
<html>
<head>
<meta charset="UTF-8">
<title>World Talk Login</title>
</head>
<body>
<?php
$form = "<form action='./login.php' method='post'>
<table>
<tr>
<td>Username:</td>
<td><input type='text' name='user'/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='password'/></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='loginbtn' value='Login'/></td>

</tr>
</table>
</form>";


if ($_POST['loginbtn']){
$user = $_POST ['user'];
$password = $_POST['password'];

if ($user) {
if ($password){
echo "$user - $password <hr /> $form";
}
else
echo "You must enter your password. $form";
}
else
echo "You must enter your username. $form";
}
?>

</body>
</html>

Answer

Try changing your php at the bottom to the following.

if ($_POST['loginbtn']){
    $user = $_POST ['user'];
    $password = $_POST['password'];

    if($user != "" && $password != "") {
        echo "$user - $password <hr /> $form";
    }

    if($user == "") {
        $error .= "You must enter your username.</br>";
    }

    if($password == "") {
        $error .= "You must enter your password.";
    }

    if($error != "") {
        echo $error.$form;
    }
} else {
    echo $form;
}
Comments