Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post

    why always error at the end?

    PHP Code:
    <?php
        
    if(!$USERNAME || !$PASSWORD) {
        
    fieldsBlank(); 
        die(); 
        } 

        if(isset(
    $NewUser)){ 
            if(!(
    $file=fopen("password.txt""append"))){ 
                print (
    "<title>Error</title></head><body> Could not open password file </body></html>");
                die(); 
            }
            
    fputs($file,"$USERNAME,$PASSWORD\n"); 
            
    userAdded($USERNAME);
            }
            else { 
                if(!(
    $file=fopen("password.txt""read"))){
                print (
    "<title>Error</title></head>Could not open password file</body></html>"); 
                die(); 
            }
            
            
    $userVerified=0
            
            while(!
    feof($file)&&!$userVerified){
                
    $line=fgets($file,255); 
                
    $line=chop($line); 
                
    $field=split(",",$line,2); 
                
                
    //verify username...    
                    
    if($USERNAME==$field[0]){ 
                    
    $userVerified=1
                    
                        if(
    checkPassword($PASSWORD,$field)==true){
                        
    accessGranted($USERNAME);
                        }else{ 
                        
    wrongPassword(); 
                        }
                    }
                    
                    
    fclose($file); 
                    
                    if(!
    userVerified){
                    
    accessDenied(); 
                    } 
                    
                function 
    checkPassword($userpassword$filedata){ 
                    if(
    $userpassword==$filedata[1]){ 
                        return 
    true; }
                        else {
                        return 
    false
                        } 
                }
                function 
    userAdded ($name
                { print (
    "enjoy the site, $name"); 
                }
                
                function 
    accessGranted ($name
                { 
                print (
    "Permission granted, $name"); 
                }
                
                function 
    wrongPassword()
                {
                print (
    "You entered invalid password"); 
                }

                function 
    fieldsBlank()
                { 
                print (
    "Please fill in all blanks"); 
                } 
                
    ?>


    I am wondering what part in script that always generates
    "
    Parse error: syntax error, unexpected $end in D:\xampp\htdocs\projects\password2.php on line 70"

    while line 70 is the last line...
    I know I am missing something, for sure
    I dont quite understand this script though .particulary $name part...
    I typed it from book, directly

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Ok, you forgot to close your while loop on line 23, also you forgot to close your else on line 15

    PHP Code:
    <?php
        
    if(!$USERNAME || !$PASSWORD) {
        
    fieldsBlank(); 
        die(); 
        } 

        if(isset(
    $NewUser)){ 
            if(!(
    $file=fopen("password.txt""append"))){ 
                print (
    "<title>Error</title></head><body> Could not open password file </body></html>");
                die(); 
            }
            
    fputs($file,"$USERNAME,$PASSWORD\n"); 
            
    userAdded($USERNAME);
            }
            else {  
    // --------------------- Line 15
                
    if(!($file=fopen("password.txt""read"))){
                print (
    "<title>Error</title></head>Could not open password file</body></html>"); 
                die(); 
            }
            
            
    $userVerified=0
            
            while(!
    feof($file)&&!$userVerified){ // --------------------- Line 23
                
    $line=fgets($file,255); 
                
    $line=chop($line); 
                
    $field=split(",",$line,2); 
                
                
    //verify username...    
                    
    if($USERNAME==$field[0]){ 
                    
    $userVerified=1
                    
                        if(
    checkPassword($PASSWORD,$field)==true){
                        
    accessGranted($USERNAME);
                        }else{ 
                        
    wrongPassword(); 
                        }
                    }
                    
                    
    fclose($file); 
                    
                    if(!
    userVerified){
                    
    accessDenied(); 
                    } 
                    
                function 
    checkPassword($userpassword$filedata){ 
                    if(
    $userpassword==$filedata[1]){ 
                        return 
    true; }
                        else {
                        return 
    false
                        } 
                }
                function 
    userAdded ($name
                { print (
    "enjoy the site, $name"); 
                }
                
                function 
    accessGranted ($name
                { 
                print (
    "Permission granted, $name"); 
                }
                
                function 
    wrongPassword()
                {
                print (
    "You entered invalid password"); 
                }

                function 
    fieldsBlank()
                { 
                print (
    "Please fill in all blanks"); 
                } 
                
    ?>


  •  

    Posting Permissions

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