Posted inMysql / Mysqli / php

PHP MySQL Insert Data – How to insert data dynamically in MySQL using PHP? | php my sql insert

php my sql insert – Insert Data Into MySQL Using MySQLi and PDO – Inserting Data into a MySQL Database Table. This article displays you how to use the MySQL INSERT INTO SELECT statement to insert data into a table with example.

php my sql insert – PHP MySQL Insert Data

php my sql insert – PHP MySQL INSERT Query For insert data in MySQL first i have to make a table in data base. The INSERT INTO statement is used to insert new rows in a database table.

Here i using 3 main file for insert data in MySQL:

  • db_config.php:For connecting data base
  • insert.php:for getting the values from the member
  • do_submit.php:A PHP file that process the request

Insert Data Into MySQL Using PHP

CREATE TABLE `member` (
	`memberid` int(8) NOT NULL,
	`member_fname` varchar(55) NOT NULL,
	`member_lname` varchar(55) NOT NULL,
	`address` varchar(55) NOT NULL,
	`email` varchar(50) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

For connecting data base

db_config.php


for getting the values from the member

insert.php



  
	
First name:

Last name:

Address:

Email Id:


A PHP file that process the request

do_submit.php


Alternative Code in (PDO)

setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
   $sql = "INSERT INTO member (member_fname,member_lname,address,email,datetime)
    VALUES ('$member_fname', '$member_lname','$address','$email','$insertdate')";
    $link->exec($sql);
    echo "New member created successfully";
    }
catch(PDOException $e)
    {

    	echo $sql . "
" . $e->getMessage(); } $link = null; ?>

Also Read: CRUD in PHP

I hope you get an idea about php my sql insert.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype