Showing errors at registration

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
tonchily
Forum Commoner
Posts: 54
Joined: Thu Sep 02, 2010 10:44 am

Showing errors at registration

Post by tonchily »

Hi.

I've created the html form and a way to process data to mysql database, but what I want to do is handle errors. For example if user tried to register with invalid email format and username containing invalid characters, I want both to be shown once he tries to register. All I managed to do now is one error at a time (by doing if statements, starting from username via password to email. First it checks for valid username, then it checks for valid password, then it checks for valid email and returns one error at a time, depending of which error statement returned false so the script stops there)

I hope you can help me.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Showing errors at registration

Post by califdon »

There are many ways of handling user errors. First of all, you can check anything that doesn't require server resources (such as a database) in Javascript before sending the form data to the server (you can even check the items that require server resources if you use Ajax). In fact, you should validate user inputs both in the browser (Javascript) and after your PHP script receives the data. Also, you don't have to return the error message to the server after checking each field. One way to do it is to create an array and add any error messages to the array until your checks are all done, then send any messages that may have been stored in the array, all at once.
Post Reply