After looking about for a bit I've created a PHP form which I want to save the data when an error is thrown. The odd thing about this is that it works when I test it in a local WAMP installation, but as soon as I move it to the server hosted online it doesn't.
My form is this:
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post" enctype="multipart/formdata"><div class="formlabel">Username:</div>
<input type="text" id="username" name="username" value="<?= @$_POST['username'] ?>"/>
<small class="errorText"><?php echo $throwError["username"]; ?></small>
<br><div class="formlabel">Password:</div>
<input type="password" id="password" name="password" value="<?= @$_POST['password'] ?>"/>
<small class="errorText"><?php echo $throwError["password"]; ?></small>
<br>
<small class="errorText"><?php echo $throwError["validate"]; ?></small>
<input type="submit" name="submit" value="Login"/>
</form>
And currently when it runs, this is the action:
$throwError = array(
"username" => "",
"password" => "",
"validate" => ""
);
if(isset($_POST['submit'])) {
$username = trim($_POST['username']);
$password = trim($_POST['password']);
setCookie('memberID', $username);
if (!empty($username) && !empty($password)) {
$result = mysql_query("SELECT * FROM member WHERE member_id='$username' AND password='$password'", $linkid);
if(!$result || mysql_num_rows($result) <= 0) {
$throwError["validate"] = "Please enter a valid username and password";
return false;
}
return true;
}
if (empty($username)){
$throwError["username"] = "Please enter your username";
}
if (empty($password)){
$throwError["password"] = "Please enter your password";
}
}
When this is hosted on Wamp and viewed via localhost, if I type a username and no password (and vice versa) I see my error, and the username/password stays input into the form. However, I uploaded this to the server and all I see is <?=@_POST['username'] ?>
as a string in the input username, and likewise (but hidden) in the password box.
Not even sure this is related to the code, but perhaps there's a way to do the same thing a different way which is why I felt the need to post it.
Any theories are appreciated!