PCHomepage
Programmer
Being so spoiled by an IDE that did all this for me, I have forgotten how to do the most basic of things. I am trying to relearn when I once knew so I know this is probably a dumb question but how can I retrieve values from a form? That is, I know how to do it but for some reason I seem to be able to get only one at a time when two are required (it's a simple non-database login form).
In HTML the form, I tried echoing the variables but nothing appears UNLESS I first echo them elsewhere. It makes no sense to me.
Somehow these echoes show the variable values AND they show in the form where the same code is located. Without these the two variables are empty. The above will allow the login process to work but, because it also gives header errors, the login does not redirect. What am I missing to get both POST values?
The entire the code is here in case it helps:
The form is basic too:
Thanks in advance for any help!
In HTML the form, I tried echoing the variables but nothing appears UNLESS I first echo them elsewhere. It makes no sense to me.
Code:
$username = $_POST['UserName'];
$password = $_POST['PWName'];
echo "Session User Name Value: " . $_SESSION['UserName'] . "<br>";
echo "User Name Variable: " . $username . "<br>";
echo "Password Variable: " . $password;
Somehow these echoes show the variable values AND they show in the form where the same code is located. Without these the two variables are empty. The above will allow the login process to work but, because it also gives header errors, the login does not redirect. What am I missing to get both POST values?
The entire the code is here in case it helps:
Code:
<?php
$SiteURL = "/";
$LoginName = "admin";
$PWord = "admin";
$username = $_POST['UserName'];
$password = $_POST['PWName'];
// These diagnostic echoes allow login to complete
//echo "Session User Name Value: " . $_SESSION['UserName'] . "<br>";
//echo "User Name Variable: " . $username . "<br>";
//echo "Password Variable: " . $password;
if ($_POST['Cancel'] == "Cancel") {
header("Location: " . $SiteURL);
} elseif ($_GET['Logout'] == 1) {
$_SESSION['UserName'] = "";
header("Location: " . $SiteURL);
} elseif ($username == $LoginName && $password == $PWord) {
$_SESSION['UserName'] = $username;
header("Location: index.php");
echo "Login Test Passed"; // for diagnostic purposes
} elseif (($username && $username != $LoginName) || ($password && $password != $PWord)) {
$InstMessage = "Login failed. The Login or Password was incorrect.";
} elseif ($username == "" || $password == "") {
$InstMessage = "You must enter your Login and Password to proceed.";
}
?>
The form is basic too:
Code:
<form action="login.php" method="POST" enctype="application/x-[URL unfurl="true"]www-form-urlencoded"[/URL] name="Login">
Login: <input name="UserName" type="text" size="10" maxlength="10" onmousedown='this.value=""'><br />
Password: <input name="PWName" type="password" size="10" maxlength="10" onmousedown='this.value=""'><br />
<input name="Login" type="submit" value="Login"> <input name="Cancel" type="submit" value="Cancel">
</form>
Thanks in advance for any help!