ilikephp Posted January 22, 2009 Share Posted January 22, 2009 hello, I have a problem plz: the echo is not displayed: if($row->password != $password) { echo "I am sorry, but the passwords are not equal."; header("Location: login.php"); exit; } Link to comment https://forums.phpfreaks.com/topic/141908-echo/ Share on other sites More sharing options...
RichardRotterdam Posted January 22, 2009 Share Posted January 22, 2009 you are doing a redirect if the password isn't correct. and is "$row" an object??? Link to comment https://forums.phpfreaks.com/topic/141908-echo/#findComment-743032 Share on other sites More sharing options...
ilikephp Posted January 22, 2009 Author Share Posted January 22, 2009 I am a little bit new in php, so I brought this code from the online search. can u help plz in displaying the error messages? thx in advance... Link to comment https://forums.phpfreaks.com/topic/141908-echo/#findComment-743037 Share on other sites More sharing options...
ilikephp Posted January 22, 2009 Author Share Posted January 22, 2009 when I removed the redirect page, the msg has been displayed. but I need it to be displayed next to the : username: or password: Link to comment https://forums.phpfreaks.com/topic/141908-echo/#findComment-743039 Share on other sites More sharing options...
trq Posted January 22, 2009 Share Posted January 22, 2009 You cannot output anything prior to calling header. Without seeing more code, I'm going to provide a simple example of what I think your looking for. <?php session_start(); ?> <form method="post"> <input type="text" name="uname"> Username ? <?php echo isset($_SESSION['error']['uname']) ? $_SESSION['error']['uname']) : ''; ?> <input type="password" name="upass"> Password ? <?php echo isset($_SESSION['error']['upass']) ? $_SESSION['error']['upass']) : ''; ?> <input type="submit" name="submit"> </form> <?php if (isset($_POST['submit'])) { // Check username / password. // These values would come from the database. $username = 'foo'; $userpass = 'bar'; if ($_POST['uname'] != $username) { $_SESSION['error']['uname'] = "You provided an invalid username"; header("Location http://yourserver.com/thispage.php"); exit(); } else { if (isset($_SESSION['error']['uname'])) { unset($_SESSION['error']['uname']); } } if ($_POST['uname'] != $password) { $_SESSION['error']['upass'] = "You provided an invalid password"; header("Location http://yourserver.com/thispage.php"); exit(); } else { if (isset($_SESSION['error']['upass'])) { unset($_SESSION['error']['upass']); } } // here you can log your users in. } ?> Keep in mind that I don't think its a good idea to be so verbose about wether or not the user got there username or passowrd incorrect. I don't usually let them know which one they got right. A simple "Either your username or passowrd is invalid" is a better option.[/code] Link to comment https://forums.phpfreaks.com/topic/141908-echo/#findComment-743059 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.