Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:24:00+00:00 2026-06-01T23:24:00+00:00

How do I show a message from the php action script of a form?

  • 0

How do I show a message from the php action script of a form?

The form is a user login with these fields.

<div id="register_user_box" class="inline_form" style="position: absolute; top: 20px; right: 10px; <br/>
     <span id="user_msg"></span><br/>
     <form action="register_user.php" method="post"> 
     <input type="hidden" name="id" id="id" value="add" /> 
     <input type="hidden" name="edit_user" id="edit_user" value="y" />
     <table cellspacing="0px"> <tr><td>Username:</td></tr><tr><td>
     <input type="text" name="uname" size="30" value="" class="inline_input"/></td> </tr> <tr><td>Email:</td></tr><tr><td>
     <input type="text" name="uemail" size="30" value="" class="inline_input"/></td> </tr> <tr><td>Password:</td></tr><tr><td>
     <input type="password" name="upass" size="30" class="inline_input"/></td> </tr> <tr><td>Confirm Password:</td></tr><tr> <td> 
     <input type="password" name="cpass" size="30" class="inline_input"/></td></tr> </table></td></tr> </table> <p>
     <input class="button" type="submit" name="register" value="Register" style="float:right;"/></p>     
     </form>
</div>

The php script register_user.php checks the if the passwords match and shows an error message if they don’t. The script checks all the other fields and prints a message if necessary.

<?php

    $messages = array( 'usr_cred_req' => 'Must specify username, email, password.',
                        'usr_name_bad' => 'Bad username selection.  Select a different usrename.', 
                        'usr_name_exists' => 'Username selected already exists.  Select a different username.',
                        'usr_email_bad' => 'Bad email selection.  Select a different email.',
                        'usr_email_exists' => 'Email selected already exists.  Select a different email.',
                        'usr_pass_notmached' => 'Passwords do not match.  Type passwords again.', 
                        'usr_not_added' => 'User not added.',
                        'usr_not_updated' => 'User not updated.',
                        'usr_added' => 'User added.'
                        );

    $username = trim($_REQUEST['uname']);
    $email = trim($_REQUEST['uemail']);
    $password = md5(trim($_REQUEST['upass']));
    $copasswd = md5(trim($_REQUEST['cpass']));


    if ( $password != $copasswd ) { echo '<script> $("#usr_msg").html("'.$messages['usr_pass_notmached'].'"); </script>'; return;}
?>

The error message isn’t shown and the browser leaves the page. I’d like the browser to stay on the page and add the error message to the span user_msg.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:24:01+00:00Added an answer on June 1, 2026 at 11:24 pm

    If you don’t want the browser to leave the page when the form is submitted, then you will have to use AJAX to submit the form in the background to communicate with the server and then update the container with the error message (or something different on success).

    Alternatively, have the PHP form post to itself, check the error messages before you output your HTML and if there was an error, insert the error message in the form markup in the desired location and re-populate the form with all of the values that were originally submitted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following form that has 2 selects: <form id=form class=form_visitar method=post action=ajax/selects.php>
html in delete_define.php follows: <form action=delete_now.php onsubmit=my_funct();> <input type=submit name=my_submit class=my_submit value=submit/> </form> javascript
I wrote a php script. I want it show help message when called with
want to show a error message as a result of a form action. For
I have a simple Message table, with 2 indexes: mysql> show keys from Message;
How can I show a message to console when start script using Start-Job? I
I have a div to show a message, I want the message to appear
I have a jQuery tab script that gets content from a PHP file defined
I'm creating quick web app that needs to send a php-created message from within
I have this PHP code: $query = SELECT name, COUNT(message) FROM guestbook_message WHERE name='.$req_user_info['username'].'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.