Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a loginin page login.php. When user clicks submit button it goes to another page loginprocess.php and checks whether user is valid or not. if user is valid then it again displays the same form and layout as the login.php page but with a message "Incorrect username and password" in a p element with class="errmsg" which is within the form below the form heading. So how do i edit the p element to display the error message ?

share|improve this question
    
I would not go from page to page but this is only my opinion, I would do everything in your loginprocess.php and place a condition such as if login/password wrong echo"<p>wrong details</p><form></form>". I cannot give you more info as you did not show us any code –  keikoku92 2 hours ago

3 Answers 3

You can use .text() or .html() method for that,

$(".errmsg").text("invalid username");
share|improve this answer

I guess you can use jquery to append text to a div but this only works when you do the checking in the same page. You could also try to send a true/false value back to login.php and then use jquery to append text to the div or just echo the error with php.

share|improve this answer

Redirect user from loginprocess.php to loginprocess.php by appending a error flag at the end of the URL.

Example:
if (...) {
 header('Location : loginprocess.php?err=1');
 exit();
}

In loginprocess.php write below code before rendering

tag :

<?php
$class = '';
if(isset($_GET['err']) {
  if($_GET['err'] == 1) {
    $class = 'errmsg';
  }
}
?>
<p class="<?php echo $class;?>"></p>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.