Back-End Development PHP and database

PHP inserting values to database

PHP inserting values to database:

To insert data in database, we need a form. HTML forms can get data input from user which can be stored in database.

Forms can be submitted by two methods:

  • GET: data sent using GET is visible in the url
  • POST: generally used to send confidential data to the database.

The form tag is specified as show below:

Creating a form

  1. Form is enclosed in <form> </form> tags.
  2. Specify the method attribute as GET or POST depending on the data being sent to the php script
  3. Set the action attribute with the URL of the php script eg:request-handler.php
  4. NOTE: Each input/select/textarea field in the form should contain name attribute. Without name attribute the value submitted will not be sent to the script.
  5. A sample form

    Demo databse

    Creating:

    PHP inserting values to database

    Table

    PHP inserting values to database

    PHP inserting values to database- request-handler.php

    Example:

    Inserting values through form:

    PHP inserting values to database

    Updation in table:

    PHP inserting values to database