SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    reading/comparing vars in a flat file

    Hi,

    I am trying to read info that has been written to a flat file, search for a particular variable, and then compare it to existing ones to make sure there isn't a duplicate entry written to it.

    Ex.

    1. Users fill out a form (including username and password)
    2. Upon submission they are taken to another page which displays info they just entered so they can verify.
    3. After they okay the info and click, they are taken to page four which emails them and writes the info to a flat file.

    What I want is a way to be able to iterate through the info written to the file and compare the 'username' that the person picked to existing ones. If there is a duplicate, then force them to choose another.

    This is what I came up with. I get no errors, but it doesn't work...

    PHP Code:
      $output "$first_name\t";
      
    $output .= "$last_name\t"
      
    $output .= "$email\t";   
      
    $output .= "$user_name\t";  
      
    $output .= "$password\t";
      
    $output .= "$password_checked\t";
     
      @
    $fp fopen("$DOCUMENT_ROOT/test/follies/participants/participants.txt""a");
     
      if(!
    $fp
      {
        echo 
    "Connection failed";
        exit();

        
    $orders file("$DOCUMENT_ROOT/test/follies/participants/participants.txt"); 
      }
      else
      {
        
    $number_of_orders count($orders);
        for(
    $i=0$i<$number_of_orders$i++)
        {
          
    reset($orders[$i]);
          
    $list current($orders[$i]);
          while(
    $list)
          { 
            
    $list next($orders);
            
    //$each = explode("\n", $list);
            
    if($user_name == $list
            {
              echo
    "<script language=\"javascript\">
              alert(\"Username already being used. Please try again.\");
              window.location=\"two.php\"
              </script>"
    ;
            }
          }
    // end while    
        
    }
        
    flock($fp2); 
        
    fwrite($fp$output);
        
    flock($fp3); 
        
    fclose($fp);
      } 
    I'm attempting to go through the array one by one and compare, but obviously am doing something wrong. I can't use a DB for this either, I have to use the file.

    Thanks for any input!
    Rob

  2. #2
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually i'm not very understand of this
    reset($orders[$i]);
    $list = current($orders[$i]);

    u have echo out the $list to see whether is the result u want or not? because i think maybe over here is very funny so maybe u go and doublecheck


Bookmarks

Posting Permissions

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