Results 1 to 40 of 85

Thread: login problems

Threaded View

  1. #11
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: login problems

    and because my post was too long to make a comment afterward, here it is:

    of course, that's all untested, but it should be okay. other than the things I mentioned in that code, there are plenty of other things you can do to better this code. for example, when you query the database to see if the user exists you already know you should only be returning one result (one user per username), but you have a while looping through the results of the query. all you need to do is fetch them once, like so:
    PHP Code:
    $info mysql_fetch_assoc($query); 
    hope that at least gives you a bit of insight, or something!

    edit: oh yeah, almost forgot! instead of just printing out your errors as they happen (I didn't comment them out), consider something like this (this would be within your login validation [or just general form validation]):
    PHP Code:
    $errors = array();

    if(
    $_SERVER['REQUEST_METHOD'] == "POST"){

      if(empty(
    $_POST['username'])){
        
    $errors[] = "username was empty";
      }

      if(empty(
    $_POST['password'])){
        
    $errors[] = "password was empty";
      }

      if(empty(
    $_POST['email'])){
        
    $errors[] = "e-mail was empty";
      }

      if(
    count($errors) == 0){

        
    /* put the rest of your login logic in here, and continue checking if
         * count($errors) is 0 before you go to the next "level" of validation
         */

      
    }

    then, later on (presumably on your form):
    PHP Code:
    <h1>Login</h1>
    <?php if(count($errors)): ?>
    <h2>The following errors occurred:</h2>
    <ul>
    <?php foreach($errors as $error): ?>
      <li><?php echo $error?></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    <!-- now your form goes here -->
    Last edited by kows; Apr 10th, 2010 at 02:28 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width