PHP MySQLi Insert Query Data into Database

PHP MySQLi Insert Query Data into Database

In this Post We Will Explain About is PHP MySQLi Insert Query Data into Database With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Insert Data into Database using PHP MySQLi Example

In this post we will show you Best way to implement Insert Data From a Form Into a Database using PHP MYSQLi, hear for How to Insert Data Into MySQL Database Table Using PHP with MYSQLi with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Also Read :   PHP and MySqli CRUD Operation Tutorial for Beginners – Step By Step




In this post I will Display how to Insert record Data into mysql Database in PHP with MySQLi. First of all I make a simple database and then create a simple table after that I start to add means insert data into mysql database mysql table in php with mysqli.Latest version of the Mysqli is extended version of MySQL.so I will use Basically mysqli to all the futures access mysql database.

To add/insert record data in mysql database simple table we use Add query INSERT INTO scripts. Here we will Display Two types of the method MySQLi Procedural with MySQLi Object-oriented method to step by step connect to mysql latest database and add sample query insert data into my database.

Also Read :   Mysqli database connection in php

Database/Table

firat of all Create a simple database name Like ‘live24udb’ using given below sql source code

CREATE DATABASE `live24udb`;

Sample Create tableData

and then Run below sql scripts to make a mysql table named tbl_items

CREATE TABLE IF NOT EXISTS `tbl_items` (
  `itemID` int(11) NOT NULL AUTO_INCREMENT,
  `itemName` varchar(20) NOT NULL,
  `itemsValue` varchar(50) NOT NULL,
  PRIMARY KEY (`itemID`)
)

MySQLi Procedural Example

It data containts insert record Source code using MySQLi Procedural

 <?php
$db_server ="YOUR_HOST_NAME";
$db_user = "root";
$db_pass = "";
$db_name ="live24udb";

// Create connection
$db_con = mysqli_connect($db_server, $db_user, $db_pass, $db_name);

// Check connection
if($db_con===false)
{
	die("Could not connect::". mysqli_connect_error());
}

$sql = "INSERT INTO tbl_items(itemName,itemsValue) VALUES('Laptop','5298')";

if(mysqli_query($db_con, $sql))
{
	echo "Success! Records added successfully";
}
else
{
	echo "error" .mysqli_error($db_con);
}

mysqli_close($db_con);
 
 ?>

MySQLi Object Oriented Example

It data containts insert record Source code using MySQLi Object Oriented

Also Read :   Laravel 5.6 Insert Update Delete - Laravel 5.6 CRUD

<?php
$db_server ="YOUR_HOST_NAME";
$db_user = "root";
$db_pass = "";
$db_name ="live24udb";

// Create here DATABASE connection
$db_con = new mysqli($db_server, $db_user, $db_pass, $db_name);

//check here Database connection
if($db_con-> connect_error)
{
	die("Could not connect:". $db_con->connect_error);
}
	
	$sql = "INSERT INTO tbl_items(itemName,itemsValue) VALUES('Laptop','5298')";
	
	if($db_con->query($sql)===true)
	{
		echo "Success!, Records added succesfully";
	}
	else
	{
		echo "error" .$db_con->error;
	}
	
	mysqli_close($db_con);
	
?>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example





Example

I hope you have Got What is Insert Data into Database using PHP MySQLi And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.