How to store textarea value in database in PHP

As a PHP beginner, I know the pain of saving form values in database. But don’t worry in this tutorial I am going to to store textarea value in database.

This tutorial is for beginner you can easily learn and implement in your future web development projects.

Also Read: Insert data in Mysql using Php Form

Store textarea value in database in PHP

how to store textarea value in database in PHP

I will create only one input field and store in mysql database. This process involves following steps.

  • Create HTML form and set method attribute value as POST.
  • Apply some css to the form for better look.
  • When forms submit get textarea and trim extra spaces from it.
  • Save into the Mysql Database.
  • If textarea saves successfully then show success msg.

Create Database:

Create Database Table:

Database Connection:


In the above form, action attribute has $_SERVER['PHP_SELF'] which means form will post on the same page. If you don’t want to use $_SERVER['PHP_SELF'] then leave action attribute blank.


Also Read: User Registration in PHP

Success Message:

PHP Code on Form Submission:

All Code Together:


Posted in PHP

Author: Ahsan Zameer

I am a web developer and love to search new stuff on web. Trying different approaches and ideas to make web developing more interesting and enjoyable.