Jump to content

Recommended Posts

how can i get the echo's to display below the form instead of above, will i need to postition using CSS??

 

<div class="login">
<?php


if ($_SESSION['is_valid'] == false) {
    if (isset($_POST['login'])) { 

        $user_name = mysql_real_escape_string($_POST["user_name"]);
        $user_password = mysql_real_escape_string($_POST["user_password"]);
        $cookiename = forumcookie;
        $verify_username = strlen($user_name);
        $verify_pass = strlen($user_password);
        if ($verify_pass > 0 && $verify_username > 0) {
            $userPswd = md5($user_password);
            $userpwsd = sha1($userPswd);
            $sql = "SELECT * FROM $user WHERE user_name='$user_name' AND user_password='$userpwsd' LIMIT 1;";
            $result = mysql_query($sql) or die(mysql_error() . " in $sql");
            if (mysql_num_rows($result) == 1) {
                $row = mysql_fetch_assoc($result);
                $s_userpass = serialize($userpass);
                $_SESSION['id_username'] = $row['user_name'];
                $_SESSION['id_user_password'] = $row['user_password'];
                $_SESSION['user_level'] = $row['userlevel'];
                $_SESSION['user_id'] = $row['user_id'];
                $_SESSION['is_valid'] = true;
                if (isset($_POST['remember'])) {
                  $checked = "checked='checked'";
		         setcookie("uname", $_SESSION['id_username'], time() + 86400*100);
                  setcookie("userpw", $user_password, time() + 86400*100);
			  setcookie("check",$checked, time() + 86400*100);
             }
              header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
            } else {
                echo "Login failed. Username or Password are not correct.";
            }
        } else {
            ?>
		<p><font style="font-size:small;">You left required field(s) blank</p>
		<?php
        }
    }
$server = str_replace("?logout","",$_SERVER['PHP_SELF']);
?>
<table class="log_in"><form action="<?php echo "$server"; ?>" method="post">
<th>Welcome</th>
<tr><td align="center">Username:</td></tr><tr><td align="center"><input type="text" name="user_name"  size="16" value="<?php echo $_COOKIE['uname']; ?>" /><br /></td></tr>
<tr><td align="center">Password:</td></tr><tr><td align="center"> <input type="password" name="user_password"  size="16" value="<?php echo $_COOKIE['userpw'] ?>" /><br /></td></tr>
<tr><td align="center"><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr>
<tr><td align="centre"><input type="checkbox" name="remember" <?php echo $_COOKIE['check'] ?>> Remember Me </td></tr><tr><td align="center"><a href="register.php">[Register]</a></td></tr><tr><td align="center"><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table>
</form>
</div>
<?php 
mysql_close();
}
}
?>
</div>

Link to comment
https://forums.phpfreaks.com/topic/104085-solved-echo-posistion/
Share on other sites

Put the code below the form....?

 

That won't work since that code need to redirect in some instances.

 

Don't use echos in that code. Simply save the responses to a variable (if there are any) and then echo that response below the form.

 

<div class="login">
<?php


if ($_SESSION['is_valid'] == false) {
    if (isset($_POST['login'])) { 

        $user_name = mysql_real_escape_string($_POST["user_name"]);
        $user_password = mysql_real_escape_string($_POST["user_password"]);
        $cookiename = forumcookie;
        $verify_username = strlen($user_name);
        $verify_pass = strlen($user_password);
        if ($verify_pass > 0 && $verify_username > 0) {
            $userPswd = md5($user_password);
            $userpwsd = sha1($userPswd);
            $sql = "SELECT * FROM $user WHERE user_name='$user_name' AND user_password='$userpwsd' LIMIT 1;";
            $result = mysql_query($sql) or die(mysql_error() . " in $sql");
            if (mysql_num_rows($result) == 1) {
                $row = mysql_fetch_assoc($result);
                $s_userpass = serialize($userpass);
                $_SESSION['id_username'] = $row['user_name'];
                $_SESSION['id_user_password'] = $row['user_password'];
                $_SESSION['user_level'] = $row['userlevel'];
                $_SESSION['user_id'] = $row['user_id'];
                $_SESSION['is_valid'] = true;
                if (isset($_POST['remember'])) {
                    $checked = "checked='checked'";
                    setcookie("uname", $_SESSION['id_username'], time() + 86400*100);
                    setcookie("userpw", $user_password, time() + 86400*100);
                    setcookie("check",$checked, time() + 86400*100);
        }
                header("Location:http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]);
            } else {
                $response = "Login failed. Username or Password are not correct.";
            }
        } else {
          $response = "<p><font style=\"font-size:small;\">You left required field(s) blank</p>";
        }
    }
    $server = str_replace("?logout","",$_SERVER['PHP_SELF']);
?>
<table class="log_in"><form action="<?php echo "$server"; ?>" method="post">
<th>Welcome</th>
<tr><td align="center">Username:</td></tr><tr><td align="center"><input type="text" name="user_name"  size="16" value="<?php echo $_COOKIE['uname']; ?>" /><br /></td></tr>
<tr><td align="center">Password:</td></tr><tr><td align="center"> <input type="password" name="user_password"  size="16" value="<?php echo $_COOKIE['userpw'] ?>" /><br /></td></tr>
<tr><td align="center"><input type="hidden" name="login" value="true"><input type="submit" value="Submit"></td></tr>
<tr><td align="centre"><input type="checkbox" name="remember" <?php echo $_COOKIE['check'] ?>> Remember Me </td></tr><tr><td align="center"><a href="register.php">[Register]</a></td></tr><tr><td align="center"><a href="forgot_password.php">[Forgot Password?]</a></td></tr></table>
</form>
</div>

<?php 
    echo $response;
    mysql_close();
}
?>

</div>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.