www.webdeveloper.com
Results 1 to 4 of 4

Thread: Can't figure out why: Parse error: syntax error, unexpected T_VARIABLE

  1. #1
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    84

    Can't figure out why: Parse error: syntax error, unexpected T_VARIABLE

    Hi, What's wrong with my code? It's to do with if ( $field1 == null || $field2 == null ) { because if I remove the error check, the code works fine.
    PHP Code:
    <?php

      
    function generatePassword ($length 6)
      {
        
    // start with a blank password
        
    $password "";
        
    $possible "1234567890abcdefghijklmnopqrstuvwxyz";

        
    // we refer to the length of $possible a few times, so let's grab it now
        
    $maxlength strlen($possible);
        
        
    // set up a counter for how many characters are in the password so far
        
    $i 0
        
        
    // add random characters to $password until $length is reached
        
    while ($i $length) { 
          
    // pick a random character from the possible ones
          
    $char substr($possiblemt_rand(0$maxlength-1), 1);
          
    // have we already used this character in $password?
            
    $password .= $char;
            
    $i++;
        }

        
    // done!
        
    return $password;
      }

    //echo generatePassword();  


    // Gets DB file into an array.
    $lines file('userlist.txt'); // format = email@email.com::Firstname Lastname

    // Loop through the array and organise into 2 columns.
    foreach ($lines as $line) {
        
        list (
    $field1$field2) = split ('::'$line);

        if ( 
    $field1 == null || $field2 == null ) { 
            
    // Missing data -- Email or Name.
            
    echo "<br><br>There were empthy fields. Check the list and correct. <br><br>"
        } else {
            echo 
    '<br><br>';
            echo 
    "$field1 $field2";
            echo 
    generatePassword();  
            echo 
    '<br />';
        }
    }
    ?>
    Thanks in advance

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,225
    No parse errors for me when I copy-and-paste your code into my editor. Maybe you have some non-printing/white-space character in there? (You could try copy-and-pasting from here, too, to see if that fixes it, and make sure your editor is saving as a plain ASCII text file, or if needed, UTF-8 without BOM.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    May 2004
    Location
    chennai, tamil nadu, India
    Posts
    442
    Code:
    Can't figure out why: Parse error: syntax error, unexpected T_VARIABLE
    You haven't mentioned the line number ?
    Chris, Senior Developer,
    Php laravel developers,
    http://www.chrisranjana.com

  4. #4
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    84
    From what I remember, the line was " if ( $field1 == null || $field2 == null ) { ", but I removed this part of the code completely and got it working without error checking.
    After reading about the possible formatting problems in this post though, I've just copied the sample code to another file and ran it without error. I guess it was something to do with the file encoding then.

    Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles