Hello All:

I'm working on a project that requires me to perform a process of taking user input from a form's textarea and appending it to another text field in the database.

This field already has information in it. I want to be able to append the new value separated by a line and time&data stamp --at the point of the new addition.

Is this achievable? I realy hope someone is familar with this and can provide help.

My database is MYSQL and abviously, PHP is the scripting language.

Thanks for the time!

There is 2 ways you can do this, depending on what you have available to you at the time of saving.

If you have the data that was already in the field available in a variable, then best to just use PHP to append the addition to the string.

or you can use the SQL function CONCAT() to do it for you

UPDATE myTable SET message=CONCAT(message, '$newMessage') WHERE id=$myMessageID

as for adding a timestamp or newline you can use sprintf()

$newMessage = sprintf("\n%s - %s", date("d/m/Y"), $form_newMessage);

might check syntax, writing from memory and before bed ;)

anyway, hope this helps you.

Thank you =OTS=G-Man, for the reply. I actually figured it out last night. My solution is quite similar to one of the ones you suggested. I used the following.

$inputbox= "\n-----"."\n".' on '.date('Y-m-d H:i:s')."\n$inputbox\n--------------";

It works fine! If may however ask: If I want this new information to be appended at the top of any exiting information, how do I achieve this?

Currently, the appending is done on the bottom of any existing information.

Your thoughts!

Member Avatar

Using the previous example, just swap the parameters in CONCAT:


Thanks for the post ardav; however, I am trying to position the new data being appended at the top of the existing data...currently, it appends at the bottom.

Member Avatar

That's what my post will do.

Thanks ardav! Got it.. thanks for the post and assistance. All is well now!

The very best