www.webdeveloper.com
Results 1 to 8 of 8

Thread: PHP newbie needing some help....

  1. #1
    Join Date
    Jun 2003
    Posts
    18

    PHP newbie needing some help....

    Hey all im new to PHP and im needing some help solving a problem.
    Im using a script for a guestbook thats PHP and when a new entry is posted the newest entry goes to the bottom of the list instead of the top the way u would think it would.
    Heres the PHP script.

    PHP Code:
    <?

    if (!isset($name) || !isset($email) || !isset($message) || empty($name) || empty($email) || empty($message)) {
    print 
    "&result=Fail";
    print 
    "&errorMsg=" urlencode("Input required for all fields.");
    exit;
    }

    $email strtolower($email);

    addentry($name$email$message);

    function 
    addentry($name$email$message) {

    $posted strftime("%D %I:%M %p");

    $message stripslashes($message);

    $file fopen('entry.txt''a+');

    if (!
    $file) {
    print 
    "&result=Fail";
    print 
    "&errorMsg=" urlencode("Could not open entry.txt file. Change CHMOD levels to 766.");
    exit;
    }

    fputs($file"<font color=\"#FFFFFF\">Name:</font> $name\n<font color=\"#FFFFFF\">Email:</font> <font color=\"#990000\"><u><A href=\"mailto:$email\">$email</A></u></font><br>\n<font color=\"#FFFFFF\">Posted:</font> $posted\n<font color=\"#FFFFFF\">Message:</font> $message\n\n");
    fclose($file);

    // Send admin an email when new entry occurs
    mailAdmin($name$email$message);
    }

    function 
    mailAdmin($name$email$message) {
     
    $mailTo "you@youremail.com";
     
    $mailFrom "From: <you@youremail.com>";
     
    $mailSubject "New Guestbook Entry";
     
    $mailBody "A visitor to your site has left the following information in your guestbook:\n
     Name: 
    $name
     Email: 
    $email
     The visitor commented:
     ------------------------------
     
    $message 
     ------------------------------
     You can view the message at:
     [url]http://www.yoursite.com[/url]"
    ;
     
    mail($mailTo$mailSubject$mailBody$mailFrom);
    }

    print 
    "&result=okay";
    exit;

    ?>
    Now i really cant work out what part of the script controls the order the posts are viewed. Could someone help me work this out ?? Im sure its something simple that im missing here.

    Thanks in advance, Mental

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Using a+ will append it to the end of the file, so perhaps the code that displays the guestbook is reversing the entries?

  3. #3
    Join Date
    Jun 2003
    Posts
    18
    Hi pyro im not sure .
    Its a Flash MX guestbook and im still learning flash also.
    Do u use flash ??
    I could attach the files if u think u could help me.
    I would just email the person that sent it me but i dont want
    to bug them if i can get help on here

    Thanks again, Mental

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Sorry. I only use Flash on a beginner level. Not sure how it handles file imports, so that would make it hard to check why it is displaying newer data at the bottom rather than the top, rather than the fact that displaying new entrys on the bottom would be the default...

  5. #5
    Join Date
    May 2003
    Posts
    550
    change
    $file = fopen('entry.txt', 'a+');
    to
    $file = fopen('entry.txt', 'r+');
    But make sure the file entry.txt exists on the server, because that will not create the file if it doesn't.

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    True, that would be one way of doing it, as r+ sets the file pointer to the beginning of the file...

  7. #7
    Join Date
    Jun 2003
    Posts
    18
    Ok now that change does work but it the causes another problem.
    For the text file with the entries to be read by Flash it needs to have:

    &result=okay&entries=

    At the start of it and all entries after that.
    BUT when i change that bit of code it adds the new entries latest to the top but it wipes that bit of code and also any other entries in the text file so any ideas ??

    Thanks once again, Mental
    Last edited by mentaleruptions; 06-30-2003 at 04:48 PM.

  8. #8
    Join Date
    May 2003
    Posts
    550
    Your going to have to change the way the flash file handles things probably.

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