Showing message on same page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
binarycodes
Forum Newbie
Posts: 1
Joined: Tue Apr 27, 2010 3:26 pm

Showing message on same page

Post by binarycodes »

I have a form i designed for collecting the details of users, if the details submitted to database a summary page is displayed, b4 this form can be submitted to the database i check to know if the username of the user already exists, if yes i want a message (e.g "username exists") to be displayed in front of the username field on the same page. Please how do i achieve this?
Please i need all your help...
jraede
Forum Contributor
Posts: 254
Joined: Tue Feb 16, 2010 5:39 pm

Re: Showing message on same page

Post by jraede »

On your form handler, save all of the values that the user input as session variables. Then you can run checks to validate the user input. If the username is already taken, for instance, you can set $_SESSION['form_errors'][] = "Sorry, this username is already taken.". If there's an error, take them back to the form page, populate the input fields with the form values from the session, and then display any errors in the $_SESSION['form_errors'] array.

PHP Sessions
Post Reply