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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    HELP! Can't Write To Text File. Nothing Happens

    Here are my two files. One contains the script that sends an array of information and stores it in a text file named log.txt.

    Here is the form page.

    PHP Code:
    <html><head><title>Add Users</title></head>
    <
    body>

    <
    form action="added.php" method="post">
    Register <input type="text" size="3" name="newusers" /> users to nuance_cd log.<br />
    <
    input type="reset" value="Clear" /><input type="submit" value="Generate IDs and PWs" />
    </
    form>
     
    </
    body>
    </
    html
    Here is the .php page

    PHP Code:
    <html><head><title>Add Users</title></head>
    <body>

    <?php

    if ( isset ($_POST['submit'])) {
        
        
    $newusers $_POST['newusers'];
        
        
    $anewusers = array();
        
            
    $fp fopen('log.txt''a+'); //***added change here
                
                
    for ($num 1$num <= $newusers$num++) {
                    
    $username time() . rand(04596);
                    
    $password time() . rand(04596).'a';
                    
    $data $username "\t" $password "\r\n";
                    
    $anewusers[] = $data;
                    
    fwrite ($fp$data."\r\n");
                }
    //close loop
            
    fclose ($fp);
            
        foreach (
    $anewusers as $value) {
            print 
    $value '<br />\n'; }
        
        } else { print 
    'You forgot to fill in some information';}
        

    ?>
     
    </body>
    </html>
    Anyone who can solve the problem of why no error messages appear when no information is entered and why the log remains empty is a God. PLEASE HELP!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Have you chmodded the file with the correct write permissions? 777 is the common one but 666 should work. Its a little more secure.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,009
    Thanks
    2
    Thanked 312 Times in 304 Posts
    If you enter a number or not on the form, with the code you posted, the "You forgot to fill in some information" will always be displayed, because your submit button does not have a name and the isset ($_POST['submit'])) will never be true.

    If you are not getting these results, then are you sure the .php file is named the same as the action="..." parameter on the form or is php installed and working on your server.

    Once you correct the lack of a name="..." parameter for the submit button, your code works (at least it did on my test system.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #4
    New to the CF scene
    Join Date
    Jul 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    CFMaBiSmAd YOU ARE LEGEND. YOU HAVE DONE WHAT 4 OTHER FORUMS HAVE FAILED TO DO.


  •  

    Posting Permissions

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