Hi all,
In here, I will show you to how to insert data into mysql database from php page.
Table Of Content
- Create Database
- Create Table
- HTML Form
- HTML Style
Create Database
In here, the database is create for performing insert operation. Create database and name it whatever you want.
CREATE DATABASE `prittytimes` ;
In here ‘prittytimes’ is the database name for creating table. We create table in prittytimes database.
Create Table
Now create table and name it ‘tbl_users’
CREATE TABLE `prittytimes`.`tbl_users` ( `user_id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , `firstname` VARCHAR( 25 ) NOT NULL , `lastname` VARCHAR( 25 ) NOT NULL , `useremail` VARCHAR( 45 ) NOT NULL ) ENGINE = InnoDB;
We create ‘tbl_users’ table in ‘prittytimes’ database. And the tbl_users’ fields are user_id,firstname,lastname,useremail.
HTML Form
html form that inserts user first name , last name and email
HTML Style
HTMl page style is specified in style tag.
Full Code
PHP Data Insert Into MySql
From the above code we can clearly say that, first we specify the html part for input field like firstname, lastname,useremail. The fields are specified in input tag with name. Next is PHP part, in here first we specify database connection in php page for insert the value from form. Get the input values from form using $_POST[]method. and insert values to database from form field.
Happy coding
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.