DeanWhitehouse Posted May 4, 2008 Share Posted May 4, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/104085-solved-echo-posistion/ Share on other sites More sharing options...
DarkWater Posted May 4, 2008 Share Posted May 4, 2008 Put the code below the form....? Quote Link to comment https://forums.phpfreaks.com/topic/104085-solved-echo-posistion/#findComment-532832 Share on other sites More sharing options...
Psycho Posted May 4, 2008 Share Posted May 4, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/104085-solved-echo-posistion/#findComment-532835 Share on other sites More sharing options...
DeanWhitehouse Posted May 4, 2008 Author Share Posted May 4, 2008 thanks, i didn't even think of that. The header still works, Quote Link to comment https://forums.phpfreaks.com/topic/104085-solved-echo-posistion/#findComment-532836 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.