Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2004
    Posts
    17

    Unhappy [PHP] problem when counting a number...

    Hi there,

    I am using a php email script which (obviously) sends an email and then shows the user what they just sent.

    It is made up of two parts, sendanemail.php and confirmanemail.php Most of sendanemail.php is html, and just defines the fields for the user to send the email. I give each email an ID number, for future reference, but it seems this is going wrong.


    PHP Code:
    $body2 nl2br($body); //add visible line breaks (I think)

    $givenum count($file);
    $givenum $givenum 1;   //assigns the number


    $string "$givenum|$subject|$body2|$ip|$date|$time
    "
    // Creates data to be added to the text file.


    fputs($myFile$string); // Writes the data ($string) to the text file 
    There is obviously a lot more, but I think that this is all that is relevant. I found that the ID seems to be affected by the amount of lines a user adds. Although I would still like these returns to be shown to the user and in the log file. I couldn't think of any solution to this. Hopefully someone on here could help me out!?


    Many thanks in advance,
    Jon
    Last edited by jonathanbull; 10-23-2004 at 11:04 AM.

  2. #2
    Join Date
    Apr 2004
    Posts
    27
    And the $file variable is an Array or what?
    (If its not an array it will return 1 or 0 if the variable is not set.)

    How do you set it?
    what kind of error do you get?

  3. #3
    Join Date
    Oct 2004
    Posts
    17
    Literally seconds after I received email notification of your post - I managed to sort it.

    Turns out I just had to replace the \n with <br>

  4. #4
    Join Date
    Apr 2004
    Posts
    27
    Nice to hear that ;)

    I see you convert \n to <br>
    so I suppose you want to display this text in some Html file...

    So I would suggest you use another usefull function which ist
    htmlspecialchars() which will convert " or < or > or & ..... to the html frendly names.... like&amp for & ......

    nl2br(htmlspecialchars($some_text))

  5. #5
    Join Date
    Apr 2004
    Posts
    37
    BTW, here's a little tip.

    PHP Code:
    //Each line under does the same thing

    $givenum $givenum 1

    $givenum += 1

    $givenum++; 

  6. #6
    Join Date
    Apr 2004
    Posts
    27
    You forgot one

    Code:
    ++$givenum;

  7. #7
    Join Date
    Apr 2004
    Posts
    37
    whoops, oh well, 2 out of three isn't so bad.

  8. #8
    Join Date
    Jun 2003
    Location
    Fornebu, Norway
    Posts
    149
    PHP Code:
    $file './counter.txt';

    $cunt file($file);
    $count trim($cunt[0]);

    $handle fopen($file'w');
    flock($handle2);
    fputs($handle, ($count+1));
    flock($handle3);
    fclose($handle);

    echo (
    $count+1); 
    another fast counter to insert.
    - RiviEr

Posting Permissions

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