SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 35
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problem With PHP-guestbook

    Hi,

    I'm making my very first php guestbook for my sister her site. It's located here:

    http://maun.cybton.com/list.php (<-- for in an Iframe)

    But I'm having a problem with it: as you can see, it has '' in front of the message, and I have no clue what so ever what could cause it.

    Does anybody know what could cause such weird characters to appear from thin air?

    Thanks,
    Ruben

  2. #2
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you post some of the code? Might help in working out whats wrong.

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by LemoNade
    Could you post some of the code? Might help in working out whats wrong.
    The problem is probably somewhere in the php code that shows the posts:

    Code:
    LIST.PHP
    
    <?php
    
    include("header.inc");
    
    $fd = fopen ("list.txt", "r");
    while (!feof ($fd)) 
    {
    $buffer = fgets($fd, 4096);
    $lines[] = $buffer;
    }
    fclose ($fd);
    
    $result = count($lines);
    $count = $result-2;
    
    while ($count != -1)
    {
    echo (stripslashes($lines[$count]));
    $count--;
    }
    
    include("footer.inc");
    
    ?>

  4. #4
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've seen this before and it is not the code. This happens in HTML pages too. It's either something to do with the server or frontpage, I can't remember which.

  5. #5
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Then what can I do about it? It was the same on other hosts...

  6. #6
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What server is it?

  7. #7
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it's on a free german host, so I'm not sure. ^-^;

  8. #8
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Post the code that prints out the table, the problem is appearing in your HTML.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  9. #9
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes
    Post the code that prints out the table, the problem is appearing in your HTML.
    I guess you're talking about 'header.inc'. But it can't be that, since I use that for the other page too, and there you don't see those weird signs. But anyway, here is it:

    Code:
    <html>
    <head>
    <STYLE type="text/css">
    BODY 
    { 
      direction:;
      background-attachment:fixed; 
      background-color: D3B59D; 
      background-image: url(background.jpg);
      background-repeat: no-repeat;
      scrollbar-arrow-color: 660000;
      scrollbar-track-color: D5BA9E;
      scrollbar-face-color: BDA894;
      scrollbar-highlight-color: BDA894;
      scrollbar-3dlight-color: 660000;
      scrollbar-darkshadow-color: BDA894;
      scrollbar-shadow-color: 660000;
    }
    
    input {
    font-family: "Courier New", courier, mono;
    font-size: 12px;
    border-width: 1px;
    }
    
    textarea {
    font-family: "Courier New", courier, mono;
    font-size: 12px;
    color: #660000;
    background: #EADDCF;
    border: 1px solid #660000;
    }
    
    body,td,th {
    	color: #660000; font-size: 12px; font-family: "Courier New", Courier mono;
    }
    a:link {
    	color: #000000;
    }
    a:visited {
    	color: #666666;
    }
    .style3 {
    	font-size: 18px;
    	font-weight: bold;
    	font-family: "Courier New", Courier, mono;
    }
    .style15 {font-size: 12px; }
    .style16 {font-size: 12px; font-family: "Courier New", Courier, mono; color: #660000; }
    .style18 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14px;}
    .style25 {font-size: 12px; font-family: "Courier New", Courier, mono; color: #000000; }
    .style26 {font-size: 11px}
    -->
    </style>
    </head>
    <div style="left: 0px; position: absolute; top: 0px; width: 500px; height: 270px; overflow: auto;">
    <table width="100%" cellpadding="0" cellspacing="0"><tr><td>
    <center><span class="style3">GASTBOEK</span>
    
    <p><a href="guestbook.php"><span class="style16">Voeg een bericht toe</span></a> - <a href="list.php"><span class="style16">Bekijk de berichten</span></a></p>
    
    <p><table border="0" width="100%"><tr><td>

  10. #10
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This code ends, halfway through ?

    You cannot leave the HTML file unfinished like this anything could happen. Your strange characters are inserted in the final HTML after the last <td> tag in this file, I suspect because the browser is confused, as am I.

    From a quick look you are missing the following.

    1x </p>
    2 x </table>
    1 x </div>
    1 x <body>
    1 x </body>
    1 x </html>

    (but not necessarily in that order !)

    Edit:


    Just realised that you've a footer.inc as well, can you post this as this could be the bits that are missing. My mistake typed before I looked
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  11. #11
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, me again. In your list.php, what happens if you substitute the code

    PHP Code:
    $fd fopen ("list.txt""r");
    while (!
    feof ($fd)) 
    {
    $buffer fgets($fd4096);
    $lines[] = $buffer;
    }
    fclose ($fd); 
    for a hardcoded example, ie

    PHP Code:
    $buffer "this is a sample dataset etc."
    This will eliminate your picking up any stray characters from the textfile.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  12. #12
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First to comment on your 2nd post: If I replace it with $buffer = "list.php" (<--if that is right, not sure, never worked with php before), I get "Fatal error: Maximum execution time of 30 seconds exceeded in /cdcv2/www2/maun/html/list.php on line 10" after 30 sec of loading.

    And on your first post:

    Code:
    </td></tr></table></p>
    </center>
    </div>
    </td></tr></table>
    </body>
    </html>
    That's the code for the footer.inc

    BTW: I thought it would be handy to know that at first I didn't have the character problem, but the problem is, I don't know exactly when, so I can't go back to see what I changed at that moment.

  13. #13
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ruben V
    ........... If I replace it with $buffer = "list.php"
    No that won't work. Let me explain a bit more in detail.

    At the moment you are opening a file called list.txt, and reading out of it each line of text, this you are putting into an array.

    What we need to do is be sure that the problem does not originate from this file or from the way we are obtaining this information from the file. In order to do this we must replace the part of the program that gets the information from the file with something we know is correct. This was what I was asking in my previous post.

    I assumed that you had made the script and was aware of the way it performed. What you need to do is look at the list.txt file in a text editor (notepad will do, providing the file isn't too big) see the structure of the file and then replicate it (by typing , not cut and paste) into a variable. If the problem goes away then we know that the data were getting from the file is corrupt somewhere and we can investigate that further.

    If you're still not sure how to do this I suggest you attach the file to a post or PM me the file, and I (and probably a few others) will look at it for you.

    I am aware of bokehmans post and suggestion, and whilst not ruling this out find it strange that you say it worked once but not now, this to me suggests that something has changed that you are not aware of.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  14. #14
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got the basic code for a guestbook from a site and then edited it. I couldn't make a php guestbook without any knowledge of it (and I learned html as I used it, I plan to learn php on the same way)

    But I don't think the problem can come from list.txt, since if I only put &#60;b&#62;test&#60;/b&#62;, I still get the same problem.

    Also--maybe something important--it only appears at the first post. When I post my second post, it's still only at the 1st one.

    NOTE: I just tought of something. When list.txt is completely empty, I don't have wrong characters, but when I type in something I do have it. So this does mean that it originates from there, or not?

  15. #15
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Ruben V
    Also--maybe something important--it only appears at the first post. When I post my second post, it's still only at the 1st one.
    This sounds to me as if youre picking up something at the begining of the txt file that interprets itself into those characters through the HTML.

    NOTE: I just tought of something. When list.txt is completely empty, I don't have wrong characters, but when I type in something I do have it. So this does mean that it originates from there, or not?
    Then I'd almost put money on this being the problem.

    Send me a copy of list.txt
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  16. #16
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see  in your TXT file:

    http://maun.cybton.com/list.txt

    Code for writing to the file could be the problem

  17. #17
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is something very strange about that server. Don't believe me? Then capture the headers. It starts a session just by requesting that text file.

  18. #18
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Platypus
    I see  in your TXT file:

    http://maun.cybton.com/list.txt

    Code for writing to the file could be the problem
    I agree about the problem being in the writing code, if its in the txt file.

    But I don't see it in the link you've supplied ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  19. #19
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The reason you don't see it is because you are one of those strange web developers that is not using Firefox. In IE although it is there it is completely ignored.

  20. #20
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    The reason you don't see it is because you are one of those strange web developers that is not using Firefox. In IE although it is there it is completely ignored.
    Which is why I always ask to see the actual file I'm questioning, not a browsers interpretation of it.

    I do have firefox installed on my dev system, unfortunately this morning I'm on the laptop in the garden, and that only has IE.

    I've always been amazed that we developers put so much store in Firefox, when 90% of the browsing public don't even know it exists, yes it's features are great for us, but for the guy who buys a computer for the family and kids to get online ?
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  21. #21
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes
    this morning I'm on the laptop in the garden
    In the sunshine I hope! Don't worry I was only teasing you. Also isn't it strange how IE completely ignores the mime type of the text file and displays it as html.

  22. #22
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by bokehman
    In the sunshine I hope! Don't worry I was only teasing you.
    Yep, lovely morning here, the world is great and nothings going to spoil it today, not even your teasing

    Also isn't it strange how IE completely ignores the mime type of the text file and displays it as html.
    I've given up trying to understand how IE operates, it's amazing what you can get away with when your a large company and can force people to use c*** software and also force them to buy ever powerful machines just to run it. But like I said, most people don't even know the've got a choice.

    I did run up to the office to look at the file, I still think its perhaps something being put in the file on initialization, if it was on addition of records I'd expect it on every record, if it was a server quirk I'd expect it on every file served. Guess we'll have to wait until Ruben V comes back to us.

    Now where did I put the sunscreen
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  23. #23
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I'm in my garden too. The weather is beautiful here on the Costa Blanca. Not a cloud in the sky. What is is it the french say about africa starting at the pyreness. They should say paradise.

  24. #24
    SitePoint Member
    Join Date
    Jan 2005
    Location
    Belgium
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh wow, I would've never thought of viewing it in firefox. Luckely I have it ('cause I always make sure my sites also look 'good' on that), so I could look for myself. And indeed, I saw it.

    And I checked more files on firefox, but luckely list.txt is the only one in firefox with those characters. So indeed, the fault has to be in add.php. I looked at it, but I couldn't find any mistakes (but then again, I'm an uber-n00b to php, so I probably don't even notice it). Here is the code:

    Code:
    <?php
    include("header.inc");
    
    echo "<center><span class=style3>Uw bericht is verzonden</span></center>";
    
    $naam = $_POST['naam'];
    $woonplaats = $_POST['woonplaats'];
    $land = $_POST['land'];
    $geslacht = $_POST['geslacht'];
    $email = $_POST['email'];
    $homepage = $_POST['homepage'];
    $bericht = $_POST['bericht'];
    
     $date = date("H:i, d-m-Y");
    
    if (empty($naam))
    {
    $error .= "<p class=style16>Geen naam ingevuld</p>";
    }
    if (empty($bericht))
    {
    $error .= "<p class=style16>Geen bericht ingevuld</p>";
    }
    if ($error)
    {
    $z="1";
    echo $error;
    echo "<center><br><a href=\"javascript:history.go(-1)\" class=\"text\"><span class=style16>Klik hier om terug te gaan</span></a></center>";
    exit;
    }
    if ($error=="")
    {
    
    $bericht = str_replace("<", "&lt", $bericht);
    $bericht = str_replace(">", "&gt;", $bericht);
    $bericht = str_replace("\n", "<br>", $bericht);
    
    $bericht = str_replace(":)", "<img src=images/smile.gif>", $bericht);
    $bericht = str_replace(":D", "<img src=images/happy.gif>", $bericht);
    $bericht = str_replace(":(", "<img src=images/sad.gif>", $bericht);
    $bericht = str_replace(":p", "<img src=images/tongue.gif>", $bericht);
    $bericht = str_replace(":o", "<img src=images/bored.gif>", $bericht);
    $bericht = str_replace("8)", "<img src=images/cool.gif>", $bericht);
    
      echo "<p>Het volgende bericht is in het gastboek van MauN toegevoegd op ";
      echo $date;
      echo "<p>";
    
    echo "<b>Naam:</b> $naam <br>";
    echo "<b>Woonplaats:</b> $woonplaats <br>";
    echo "<b>Land:</b> $land <br>";
    echo "<b>Geslacht:</b> $geslacht <br>";
    echo "<b>Email:</b> $email <br>";
    echo "<b>Homepage:</b> http://$homepage <br></p>";
    echo "<p align=justify><b>Bericht:</b> $bericht </p><br>";
    
      $outputstring = "<p align=left><b>Naam:</b> ".$naam."<br><b>Woonplaats:</b> ".$woonplaats."<br><b>Land:</b> ".$land."<br><b>Geslacht:</b> ".$geslacht."<br><b>Email:</b> <a href=mailto:$email>".$email."</a><br><b>Homepage:</b> <a href=http://$homepage target=_blank>http://".$homepage."</a><br><b>Datum:</b> ".$date."</p><p align=justify><b>Bericht:</b> ".$bericht."</p></p><p align=left><hr color=#660000 width=200></p>\n";
    
      // open
    @ $fp = fopen("list.txt", "a");
    
    
      flock($fp, 2); 
     
      if (!$fp)
      {
        echo "<p>Uw bericht kan op dit moment niet toegevoegd worden. "
             ."Probeer a.u.b. later nog eens.</p></body></html>";
        exit;
      } 
    
      fwrite($fp, $outputstring);
      flock($fp, 3); 
      fclose($fp);
    
    }
    
    include("footer.inc");
    ?>
    Thank all 3 of you for your great help

    EDIT: The problem is probably in the $outputsring, since if you post a message, you first get a page saying 'this message is succesfully posted' or something, and then you can check what you have written (before you actually go to 'read messages'), and there you don't have those weird characters. So the problem probably will be in the outputstring because that is the code that puts it in the txt file, the only place where the info is wrong.

  25. #25
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    OK, first lets test the theroy that the characters are being put into the file on creation of the file. I'm going with this as you said that only the first entry has this problem.

    Replace your code with this
    PHP Code:
    <?php
    include("header.inc");
     
    echo 
    "<center><span class=style3>Uw bericht is verzonden</span></center>";
     
    $naam $_POST['naam'];
    $woonplaats $_POST['woonplaats'];
    $land $_POST['land'];
    $geslacht $_POST['geslacht'];
    $email $_POST['email'];
    $homepage $_POST['homepage'];
    $bericht $_POST['bericht'];
     
    $date date("H:i, d-m-Y");
     
    if (empty(
    $naam))
    {
    $error .= "<p class=style16>Geen naam ingevuld</p>";
    }
    if (empty(
    $bericht))
    {
    $error .= "<p class=style16>Geen bericht ingevuld</p>";
    }
    if (
    $error)
    {
    $z="1";
    echo 
    $error;
    echo 
    "<center><br><a href=\"javascript:history.go(-1)\" class=\"text\"><span class=style16>Klik hier om terug te gaan</span></a></center>";
    exit;
    }
    if (
    $error=="")
    {
     
    $bericht str_replace("<""&lt"$bericht);
    $bericht str_replace(">""&gt;"$bericht);
    $bericht str_replace("\n""<br>"$bericht);
     
    $bericht str_replace(":)""<img src=images/smile.gif>"$bericht);
    $bericht str_replace(":D""<img src=images/happy.gif>"$bericht);
    $bericht str_replace(":(""<img src=images/sad.gif>"$bericht);
    $bericht str_replace(":p""<img src=images/tongue.gif>"$bericht);
    $bericht str_replace(":o""<img src=images/bored.gif>"$bericht);
    $bericht str_replace("8)""<img src=images/cool.gif>"$bericht);
     
    echo 
    "<p>Het volgende bericht is in het gastboek van MauN toegevoegd op ";
    echo 
    $date;
    echo 
    "<p>";
     
    echo 
    "<b>Naam:</b> $naam <br>";
    echo 
    "<b>Woonplaats:</b> $woonplaats <br>";
    echo 
    "<b>Land:</b> $land <br>";
    echo 
    "<b>Geslacht:</b> $geslacht <br>";
    echo 
    "<b>Email:</b> $email <br>";
    echo 
    "<b>Homepage:</b> http://$homepage <br></p>";
    echo 
    "<p align=justify><b>Bericht:</b> $bericht </p><br>";
     
    $outputstring "<p align=left><b>Naam:</b> ".$naam."<br><b>Woonplaats:</b> ".$woonplaats."<br><b>Land:</b> ".$land."<br><b>Geslacht:</b> ".$geslacht."<br><b>Email:</b> <a href=mailto:$email>".$email."</a><br><b>Homepage:</b> <a href=http://$homepage target=_blank>http://".$homepage."</a><br><b>Datum:</b> ".$date."</p><p align=justify><b>Bericht:</b> ".$bericht."</p></p><p align=left><hr color=#660000 width=200></p>\n";
     
    // open
    $fp fopen("list.txt""a");
     
     
    // flock($fp, 2); 
     
    // if (!$fp)
    // {
    //    echo "<p>Uw bericht kan op dit moment niet toegevoegd worden. "
    //         ."Probeer a.u.b. later nog eens.</p></body></html>";
    //    exit;
    // } 
     
    // fwrite($fp, $outputstring);
    // flock($fp, 3); 
    fclose($fp);
     
    }
     
    include(
    "footer.inc");
    ?>
    Then go into your server and delete the list.txt file completely.

    What we've done is take out everything that actually writes to the file, by deleteing the file the fopen command will try to open the file, because it doesn't exist it will make the file and close it. You can then look at the file and see what if anything has been put inside.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming


Bookmarks

Posting Permissions

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