0

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!

whitfin
  • 4,539
  • 6
  • 39
  • 67

3 Answers3

1

Maybe if you set

short_open_tag = On 

in php.ini and restart your Apache server.

Source.

Community
  • 1
  • 1
Gaston Sanchez
  • 1,181
  • 6
  • 13
  • This did actually work for me, I set it in the .htaccess. Strange, I thought they both did the same thing! – whitfin Feb 02 '13 at 13:10
1

This - <?= @$_POST['username'] ?> is used mostly with variables in javascript where var = but else try just $_POST['username'] or similar php variables.

Javier Brooklyn
  • 624
  • 3
  • 9
  • 25
0

when you want to post data on same page leave action="" in form tag of html tag on form submit try

foreach($_post as $key=?$value)
{
print_r($key);
}

and check what it shows