Hey all you guys at DaniWeb! I have tried my hand at what I guess is Ajax, with a PHP script to execute it. The page itself renders and the form works, but the login script is not working. I'm not sure what is wrong, although I'm sure I messed something up. The code should post the user input to itself, check if the form is being posted to itself, and gives the user an answer whether or not he got the password correct. The password and username are hard coded. Here is the code:
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<title>
PHP Hardcoded Login Script!
</title>
</head>
<body>
<?php
function corrLogin() {
echo "<SCRIPT>
d = document.getElementById(\"loginStatus\");
d.innerHTML = \"Correct Login!\";
</SCRIPT>";
}
Function incorrLogin() {
echo "<SCRIPT>
d = document.getElementById(\"loginStatus\");
d.innerHTML = \"Incorrect Login!\";
</SCRIPT>";
}
$postUser = $_POST["postUser"];
$postPassword = $_POST["postPassword"];
$isSubmitted = $_POST["postToSelf"];
if($isSubmitted == "yes") {
if($postUser == "admin" && $postPassword == "pass") {
corrLogin();
}
else {
incorrLogin();
}
}
?>
<a href="http://www.thatcompdude.com">ThatCompDude PHP Login</a>
<h1 class="pagetitle">Please enter your login information:</h1>
<form action="index.php" method="post">
<h3>User: </h3><input type="text" name="postUser" />
<h3>Pass: </h3><input type="password" name="postPass" />
<input type="hidden" name="postToSelf" value="yes" />
<br/>
<input type="submit" value="Submit"/>
</form>
<div id="loginStatus">
</div>
</body>
</html>
This code can be found on my server at: http://drafts.thatcompdude.com/HaxMe/Hardcoded_PHP_Login/index.php