making a simple guestbook
If you have an html and you sumbit it to a basic PHP file receiver, I wonder how you make them add up. how do you make the submitted forms stack instead of each submission replacing the other? I have no clue where to even start looking for an answer.
开发者_开发百科wrap print statements and make wrap element an array? do i need file I/O for this so the messages get stored somewhere?
PHP is a very confusing jungle for me at the moment. Note that I haven't gotten to the database part of php in my course yet.
many thanks in advance
You could store data in files like @Col. Shrapnel has answered.
However, if you are going to create a guestbook that also will be used online, I would recommend learning to work with databases. It would be good practice.
A database helps you to organize your data in a logical manner.
Of course you will need file I/O to store messages.
Otherwise how they are supposed to be saved?
So, you have to save your messages in a file.
To add new data at the bottom of the file you have to append it instead of rewriting.
if you're using file_put_contents
function, use it with FILE_APPEND flag:
file_put_contents($file, $data, FILE_APPEND);
if you're using fopen()
, use 'a'
mode instead of 'w'
If you want to store data between submissions, you can store in is the _SESSION
variable, just call session_start
at the beginning of your program. Messages can be stored in a file, for example. You can use sqlite as a database if you wish.
What do you mean by wrapping?
精彩评论