April 3, 2016
How To Insert Data Into MySQLi Database Using PHP

In this tutorial, we going to see how to insert data into MySQL database using PHP. INSERT statement is used to insert data into a MySQL database table. Now we do a SQL query using the INSERT statement with proper values, following that we will execute this insert query through passing it to the PHP mysqli_query() function to insert data into the MySQL table. There is an example, which inserts a data into the infom table by specifying values for the name, lname and age.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php $server = "localhost"; $user = "root"; $pass = ""; $dbname = "info"; //Creating connection for mysqli $conn = new mysqli($server, $user, $pass, $dbname); //Checking connection if($conn->connect_error){ die("Connection failed:" . $conn->connect_error); } $query = "INSERT INTO infom (name, lname, age) VALUES ('Mohan', 'raj', '23')"; if($conn->query($query) === TRUE){ echo "Record Added Sucessfully"; } else { echo "Error" . $query . "<br/>" . $conn->error; } $conn->close(); ?> |
Download
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]