Home
Username:
Password:
PHP Tutorials

Sessions and Users / Registering a User pt. 2




Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.


Learn More

Subtitles of the Movie

If this result here that is to say the result of the query where we’re trying to add the new username and password to the database was false, then we need to let them know that something has gone wrong. So we’re simply going to echo this error message and finish executing the script. In a real life situation we may want to do something a little more graceful at least to give the email address where the user is able to contact our technical member of staff to report the error and even better to use a system where by the error would be automatically logged however for the sake of our simple log in system, we’re going to throw up the error message and we’re going to need another ‘else’ statement down here and this ‘else’ statement, if we look carefully at the indentation refers to this 'if' statement up here. So if a result was found from this query and this query if you remember is to test whether the user name that the user has just entered has already been entered on the database. So if the result is anything other than 0, then we have a problem and we need to tell them that user name has already been taken. Quick message and we’re not going to put an exit there because we need them to try again using this form. Finally there is one more ‘else’ statement that we’re going to need and that's up here, we asked if the user variable and the password variable had both been filled. However it’s possible that the user as we saw on the login form could have simply entered one but not the other and so we'll use an 'or' condition down here to test for that eventuality and then if that happens, we'll want to let them see the form again straight afterwards. So there is our html form and that's our register page. We'll save that and then we'll test out this whole system in the browser once again. Let’s try our registration and we’re going to try a wholly new user name, our user name is going to be Kermit and our password will be frog. Our details have been added, we can go to the main page, we can logout and we can log in using the details that we have just added. Our little log in system therefore works just fine. I recommend that you try out these scripts yourselves either re writing them to suit your specifications or just making little alterations and examining each part of the scripts so that you’re really familiar with how it works. So that's it for this chapter on sessions and users and in our next chapter we’re going to cover php's object handling.

Tutorial Information

Course: PHP
Author: Joshua Mostafa
SKU: 33332
ISBN: 1889347787
Release Date: 2002-03-26
Duration: 9.5 hrs / 92 lessons
Work Files: Yes
Captions: For Online University members only
Compatibility: Vista/XP/2000, OS X, Linux
QuickTime 7, Flash 8

VTC Sign up & Benefits

  • Unlimited Access
  • 98,729 Video Tutorials (23,265 free)
  • Video Available as Flash or QuickTime
  • Over 1026 Courses
  • $30 for One Month Access
  • Multi-User Discounts Available