Find the answer to your Linux question:
Results 1 to 9 of 9
Like Tree1Likes
  • 1 Post By elija
The following is a function that doesn't seem to work but it looks like it should. Unfortunetly XAMPP complains. Code: function write_information($personnel) { $integer = 0;$contiguous = $personnel;$metamorph = NULL; ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! errigour's Avatar
    Join Date
    Jan 2009
    Posts
    52

    why doesn't this function work


    The following is a function that doesn't seem to work but it looks like it should. Unfortunetly XAMPP complains.
    Code:
    function write_information($personnel)
    {
            $integer = 0;$contiguous = $personnel;$metamorph = NULL;
    	for($integer == 0; $contiguous[$integer] != NULL; $integer++)
    	{
    	        if(is_int($contiguous[$integer]) == FALSE)
    		{
                            $metamorph = $contiguous[$integer];
    		}
    		else
    		{
    			$metamorph = $contiguous[$integer];
    		}
    	}
    	fputs($handle, $personnel."\n");
    }
    if($_POST["password"]){write_information($_POST["password"]);}
    I get these errors
    Code:
    Notice: Uninitialized string offset: 9 in C:\Documents and Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\login\create+account.php on line 60
    
    Notice: Undefined variable: handle in C:\Documents and Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\login\create+account.php on line 71
    
    Warning: fputs() expects parameter 1 to be resource, null given in C:\Documents and Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\login\create+account.php on line 71

  2. #2
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,482
    The thing that is is stopping it working is that you haven't opened a file to write to and therefore the file handle ($handle) is null. Although I'm not sure what the aim of the function is, at one point you seem to be saying
    Code:
                if(is_int($contiguous[$integer]) == FALSE)  //  If this is true then
            {
                            $metamorph = $contiguous[$integer];  //  do this
            }
            else  //  otherwise
            {
                $metamorph = $contiguous[$integer];  //  do exactly the same thing and then completely ignore the result
            }
    You could also change your for loop from
    Code:
    for($integer == 0; $contiguous[$integer] != NULL; $integer++)
    to
    Code:
    for($integer = 0; $integer < count($contiguous); $integer++)
    . The bolded bit in the original code is testing for equality rather than assigning.

    In fact, unless that's just a snippet, you could lose the entire for loop and get the same effect.
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  3. #3
    Just Joined! errigour's Avatar
    Join Date
    Jan 2009
    Posts
    52

    That was just a section of the code

    That was just a section of the code, the handle is defined and works great for every other part of the code inside the same if statement as that is. That's the reason i'm asking what the problem is. Also I haven't finished the function that's why it does the same thing in both statements. I plan to make that function encrypt the password. Also I want to ask will that for loop of mine give me any other characters other then the password. I seem to be using it until it is NULL but I only want to use the loop for changing the password characters not any other characters like end of line. Lastly I have one more question and that is if you new of any functions that would help me encrypt passwords not excluding common functions.
    Code:
    if (!$handle = fopen("database/".$_POST["username"], "w+"))

  4. #4
    Just Joined! errigour's Avatar
    Join Date
    Jan 2009
    Posts
    52

    Heres the new errors after fixing it

    Here are the new errors after fixing what you pointed out.
    Code:
    Notice: Uninitialized string offset: 9 in C:\Documents and
    Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\login
    register.php on line 60
    
    Notice: Undefined variable: handle in C:\Documents and 
    Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\login
    \register.php on line 71
    
    Warning: fputs() expects parameter 1 to be resource, null 
    given in C:\Documents and Settings\iceweasel\Desktop
    \XAMPP\relik.ath.cx\login\register.php on line 71

  5. #5
    Just Joined! errigour's Avatar
    Join Date
    Jan 2009
    Posts
    52
    Ok I just added a handle variable to the function and now it writes with the function but I still have one last problem and that is the offset error message above. I think it's talking about the NULL variable I used which isn't defined but I have no substitute for.

    here's the line,
    Code:
    for($integer = 0; $contiguous[$integer] != NULL; $integer++)
    here's the error again,
    Code:
    Notice: Uninitialized string offset: 9 in C:\Documents and
    Settings\iceweasel\Desktop\XAMPP\relik.ath.cx\login
    register.php on line 60
    The weird thing is I used the variable NULL one line above it with no problems.

  6. #6
    Just Joined! errigour's Avatar
    Join Date
    Jan 2009
    Posts
    52
    Heres the line right before that line.
    $integer = 0;$contiguous = $personnel;$metamorph = NULL;

    You can see what I mean by it not being bothered by my first
    decleration using NULL

  7. #7
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,482
    Quote Originally Posted by errigour View Post
    Heres the line right before that line.
    $integer = 0;$contiguous = $personnel;$metamorph = NULL;

    You can see what I mean by it not being bothered by my first
    decleration using NULL
    You can find the answer to that here
    Mudgen likes this.
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    Conkybots: Interactive plugins for your Conkys!

  8. #8
    Just Joined! errigour's Avatar
    Join Date
    Jan 2009
    Posts
    52
    The link brings me to this page

  9. #9
    Linux User sgosnell's Avatar
    Join Date
    Oct 2010
    Location
    Baja Oklahoma
    Posts
    462
    To a particular post on this page. Read it carefully.

Posting Permissions

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