Skip to content
Advertisement

Insert two values into MariaDB table using a textarea in HTML – PHP

I’m trying to add some text from a TEXTAREA in HTML to my table in mariaDB using PHP in Linux. Basically the form has two “boxes”. One to identify the user and the second one to add a text. If the user have already added a text, will not be possible to add more text. I am struggling to add the name and the text from TEXTAREA (from HTML) using a query in PHP. Any ideas??

This is my table in MariaDB:

JavaScript

This is my form in html:

JavaScript

and this is my code in PHP:

JavaScript

Advertisement

Answer

Missing comma between values try

JavaScript

Also turn on PDO exceptions:

JavaScript

You’ll see an error in your case (or maybe some other)

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 1364 Field ‘date’ doesn’t have a default value in …

If you’ll allow date field to be null or always will insert valid date record will be inserted.

Just tested.

Also! Make sure that $_POST['name'] and $_POST['textmessage'] are sent.

As I can see, in form you have name="message" but trying to fetch textmessage. Pls fix all these bugs first. Use debugger and browser’s inspector to make sure all required data arrives to the script.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement