• Have Any Question?
  • contact@eitworld.com

MySQLi Insert Data





  • Insert Into query is used to insert data into table. It would be more precise to say that this query is used to add new records in the database table.

Syntax

Syntax1

INSERT INTO tableName(column1, column2…) VALUES (value1,value2…);
  • On execution of above query, the values will be added to their corresponding column. It is not necessary to write the column names in the same order as they are in the database table.

Syntax2

INSERT INTO tableName VALUES(value1,value2…);

In this syntax, column names are not defined. So the values will be inserted in the columns in same order as they appear in the database table.

Example

  • These queries must be given as the second parameter of the function mysqli_query(). See the example.

<!DOCTYPE html>
<html><body>

<?php

$connect=mysqli_connect(“localhost”,”root”,””,”firstdb”);

$query=”INSERT INTO employee(id,name,salary,contact) VALUES(‘1′,’John’,’25000′,’7777777′)”;

mysqli_query($connect,$query);

$query=”INSERT INTO employee VALUES(‘2′,’Peter’,’40000′,’9999999′)”;

mysqli_query($connect,$query);

?>

</body>

</html>

Output

The table will look like:

id name salary contact
1 John 25000 7777777
2 Peter 40000 9999999
  • Above example clarifies both syntaxes. It will add two rows in the table emplayee of database firstdb.


Real Time Web Analytics