PHP - Insert data into MySql server

the mysql insert into statement is used to insert new record in a table.

in other word the mysql insert statement allows you to insert data into tables.

mysql insert into syntax

you can write the insert into statement in two forms.

the first form does not specify the column names where the data will be inserted,only their values:

             insert into      table_name1

             values (data1, data2, data3 ....);

the second form specifies both column names and the values to be inserted.

            insert into      table_name1   (column0,column01,....)

             values (data1, data2, data3 ....);

we can insert more than one record at a time using insert into statement.

            insert into      table_name   (column1,column2,....)

             values            (value1, value2, value3 ....),
              
                                   (value1, value2, value3 ....),
                                                 
                                   (value1, value2, value3 ....),
                                                 
                                   ....;

the php use mysqli_query() function to execute the insert into statement and send query to a mysql server.

 <?php
    
          $host_name = "localhost";
               
          $user_value = "mobile";
               
          $pass_value= "tuch";
               
          $db_value = "applemobile";               
               
     //'mysqli procedural style use to connect mysql database server ____'
                
 $con_object = mysqli_connect( $host_name, $user_value, $pass_value, $db_value);

  if( $con_object ){ echo  "<h5>'connection success'</h5>";
                  
                 }else {              
     
  echo  "<h5>connection fail - error :-- ". mysqli_connect_error() ."<h5>"; 
  
                   }
         
   mysqli_query( $con_object,   "insert into         users

                                                              values  ('shyam', 'sing',  95492)");
              
   mysqli_query( $con_object,   "insert into users (firstname,lastname)

                                                              values  ('krishna', 'nehra')");          
  ?>