• 0

PHP Form Help


Question

Bare with me people. I'm learning PHP, this logon page i made in a form just something simple, prints out something if the login info is correct. But i think i might be doing this wrong. Im not to sure if you can use if statement around html code. If someone can help me out that would be awesome. Thanks guys.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LOGIN</title>
</head>

<body>

<?php

if (!$_POST['submitbtn'] {

?>
<div align="center"><strong>LOGIN: <br /><br />
</strong></div>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="loginfrm"><br /><br />

 Login:  <input name="username" type="text"/><br /><br />


Password  <input name="pass" type="password" /> <br /><br />


  <input name="submitbtn" type="submit" value="Submit" />
</form>

<?php
}
else {
if ($_POST['username'] == "Duddy") && ($_POST['pass'] == "Password")
echo "welcome to the secret area";	
}

?>
</body>
</html>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Bare with me people. I'm learning PHP, this logon page i made in a form just something simple, prints out something if the login info is correct. But i think i might be doing this wrong. Im not to sure if you can use if statement around html code. If someone can help me out that would be awesome. Thanks guys.

You can use an IF statement to limit what is displayed, theres nothing wrong with doing that. There is an error in your code however.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>LOGIN</title>
</head>

<body>

<?php

if (!$_POST['submitbtn']) {

?>
<div align="center"><strong>LOGIN: <br /><br />
</strong></div>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" name="loginfrm"><br /><br />

 Login:  <input name="username" type="text"/><br /><br />


Password  <input name="pass" type="password" /> <br /><br />


  <input name="submitbtn" type="submit" value="Submit" />
</form>

<?php
}
else {
if ($_POST['username'] == "Duddy" && $_POST['pass'] == "Password"){
echo "welcome to the secret area";
}
}

?>
</body>
</html>

try that :D i havent tested it though.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.