Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Making a guestbook

dvrslypedvrslype Member Posts: 50
Hi,

i'm totally new at PHP and my first thing i wanted to make isn't what it should be:

Everything can be checked at http://members.lycos.nl/dvrslype/gastenboek.php

and the code is http://members.lycos.nl/dvrslype/GuestBook.zip.

the entries are stored in a file like this:

[code]
<?php
$uitvoer[] = $naam;
$uitvoer[] = $comment;
$uitvoer = serialize($uitvoer);
if($file = fopen("data.txt","a+"))
{
fwrite($file,$uitvoer);
fclose($file);
}
?>
[/code]

and then I build my guestbook like this:

[code]
<?php
$alledata = file("data.txt");
echo "Aantal entry's : " . count($alledata) . "<br>";

while(list($key,$data) = each($alledata))
{
$gegevens = unserialize($data);
echo "

";
echo "Naam: " . $gegevens[0] . "
";
echo "Commentaar: " . $gegevens[1] . "
";
}
echo "

";

?>
[/code]

But it only wants to take 1 entry. Even if everything it should store, is stored in data.txt (and it does). WTF is wrong?

thx in progress,

dvrslype

Comments

  • SouldrinkerSouldrinker Member Posts: 143
    Hi there,

    Just try something like this to store data in your guestbook-flat-text-File you use (probably it is better to use a database instead of flat files, but here it goes...)

    [code]

    $old_content = join ( "", file ( "path_and_file" ) );

    $fh = fopen ( "path_and_file", "w" );

    fputs( $fh, $old_content );
    fputs( $fh, "new_entry" );

    fclose ($fh);

    [/code]

    why this works better?

    appendfunctions did never work in my tests, not correctly - maybe I'm to stupid to use them, but this is how some "a+" mode will work on the file :)

    Have a lot of fun!
    best regards,

    sebastian mohrenstecher
    executive secretary
    net::allies

    www.net-allies.de
    info@net-allies.de

  • Shawn CarterShawn Carter Member Posts: 0

    ___ [ http://forcoder.org ] free video tutorials and ebooks about [ Perl, Objective-C, Visual Basic .NET, Go, Assembly, Python, C++, Ruby, MATLAB, JavaScript, PL/SQL, PHP, Java, Delphi, Visual Basic, C, Swift, C#, Scratch, R Transact-SQL, SAS, Hack, Rust, Erlang, Clojure, ML, Dart, F#, LabVIEW, COBOL, Prolog, Lua, Scala, Logo, Bash, Alice, Apex, Lisp, Kotlin, Fortran, Awk, D, Julia, FoxPro, ABAP, Scheme, Crystal, Ada, VBScript ] ____________

Sign In or Register to comment.