Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Help with code

  1. #1
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    PHP Code:
    <?php
    $user
    =$_POST['user'];
    $pass=$_POST['password'];
    $ann=$_POST['announcement'];
    $add=$_POST['add'];
    $filename "announcement.txt";
    $fp fopen($filename"r") or die("Couldn’t open $filename");
    $line =  fread($fpfilesize($filename));
    fclose($fp);
    if(
    add == "true" && user="USER_NAME" && pass="PASS")
    {
    $fp fopen($filename"w") or die("Couldn’t open $filename");
    fwrite($fp$line '<br />' $ann);
    echo(
    '<html><head><title>Success</title></head><body><h1>file write success</h1><a href="http://ls-design.forthelads.net">home</a></body></html>')
    }
    if(
    add == "false" && user="USER_NAME" && pass="PASS")
    {
    $fp fopen($filename"w") or die("Couldn’t open $filename");
    fwrite($fp,$ann);
    echo(
    '<html><head><title>Success</title></head><body><h1>file write success</h1><a href="http://ls-design.forthelads.net">home</a></body></html>')
    }
    else
    {
    echo(
    '<html><head><title>Failed</title></head><body><h1>file write failed</h1><a href="http://ls-design.forthelads.net">home</a></body></html>')
    }
    fclose($fp);
    ?>
    The above code doesn't work please help. the form it is submitted from is
    http://ls-design.forthelads.net/cmessage.html
    Please help i have little experence in php
    Thee Pyro Wolf

  2.  

  3. #2
    Senior Member Fallout's Avatar
    Join Date
    Aug 2003
    Location
    Richmond, Virginia
    Posts
    543
    Member #
    2748
    Can you say what data this accepts and what it is supposed to be doing?

  4. #3
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    A couple of things and my guess about your problem:

    PHP Code:
    /*line 9 should be*/
    if($add == "true" && $user=="USER_NAME" && $pass=="PASS")

    /* line 15 should be */
    if($add == "true" && $user=="USER_NAME" && $pass=="PASS"
    the variables are missing $ sign and you need two = signs in the if statements to evaluate.

    PHP Code:
    $fp fopen($filename"r") or die("Couldn’t open $filename");
    $line =  fread($fpfilesize($filename));
    fclose($fp); 
    can be replaced by a one-liner:
    PHP Code:
    $line file_get_contents($filename); 
    Also, when you are appending to the announement file, open the file with "a" mode, that will eliminate the need to read the contents in beforehand.
    There and Back Again :Ogre:

  5. #4
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    Thanks, By the way the code is supposed to require a user and pass and then change the contents of the file to the submitted text overwriteing if add is false.
    the file is embeded into a page to dynamicly update announcements
    Thee Pyro Wolf

  6. #5
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    I am still having a problum i uploaded the file this time:
    the site:http://ls-desing.forthelads.net/cmessage
    (NOTE:the user and pass have obviously been replaced)
    Thee Pyro Wolf

  7. #6
    Senior Member MoRpHeUs's Avatar
    Join Date
    Apr 2005
    Location
    UHS-VILLE
    Posts
    139
    Member #
    9568
    I am still having a problum i uploaded the file this time:
    the site:http://ls-desing.forthelads.net/cmessage
    (NOTE:the user and pass have obviously been replaced)
    NOTE:link http://ls-design.forthelads.net/cmessage.html is the proper link as the other one has been misspelled.

    I'm not here for you, I'm here to raise your discomfort

  8. #7
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    Thank you for correcting that error...
    Thee Pyro Wolf

  9. #8
    Senior Member nsr81's Avatar
    Join Date
    Oct 2002
    Posts
    1,132
    Member #
    250
    Liked
    15 times
    Your variables are still missing the dollar signs. Try this code with correction:

    PHP Code:
    <?php
    $user
    =$_POST['user'];
    $pass=$_POST['password'];
    $ann=$_POST['announcement'];
    $add=$_POST['add'];
    $filename "Announcement.txt";
    $line file_get_contents($filename); 
    if(
    $add == "true" && $user=="USER_NAME" && $pass=="PASS_WORD")
    {
    $filename fopen($filename"w") or die("Couldn’t open $filename");
    fwrite($filename$line '<br />' $ann);
    echo(
    '<html><head><title>Success</title></head><body><h1>file write success</h1><a href="http://ls-design.forthelads.net">home</a></body></html>');
    }
    if(
    $add == "false" && $user=="USER_NAME" && $pass=="PASS_WORD")
    {
    $filename fopen($filename"w") or die("Couldn’t open $filename");
    fwrite($filename,$ann);
    echo(
    '<html><head><title>Success</title></head><body><h1>file write success</h1><a href="http://ls-design.forthelads.net">home</a></body></html>');
    }
    else
    {
    echo(
    '<html><head><title>Failed</title></head><body><h1>file write failed</h1><a href="http://ls-design.forthelads.net">home</a></body></html>');
    }
    fclose($filename)
    ?>
    There and Back Again :Ogre:

  10. #9
    Senior Member MoRpHeUs's Avatar
    Join Date
    Apr 2005
    Location
    UHS-VILLE
    Posts
    139
    Member #
    9568
    fclose($filename) - this was the one that was giving you trouble, was it not pyrodragon?

    I'm not here for you, I'm here to raise your discomfort

  11. #10
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    that was true although the above did solve the problum... Assumeing the error was caused by incorrect variable nameing
    Thee Pyro Wolf


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:47 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com