articles

Home / DeveloperSection / Articles / Inserting Record in MySQL database Table using PHP

Inserting Record in MySQL database Table using PHP

Anonymous User7286 21-Sep-2011

INSERT INTO Statement is used to insert new record into table.

Syntax:
INSERTINTO table_Name ( column_name1, column_name2, .....column_nameN)
  VALUES (value1, value2,........valueN)
Example:
<?php
 
    // creatingconnection with mysql database server
 
    $con = mysql_connect("localhost", "root", "root");
    // check connection is establish or not
    if(!$con)
    {
        die ("Connectionnot established! Please try again");
    }
 
    //Selecting databse
    mysql_select_db("TempDatabase",$con);
 
    // Insertingrecord into tblTemp
    $qry = "INSERT INTO tblTemp
            VALUES
            (
                '102',
                'Singh',
                'xyz@pqr.com',
                'Hn-xyz pqr ',
                '000000000'
            )";
 
    // Executingquery in MySql database server
    if(mysql_query($qry,$con))
    {
        echo 'Record inserted successfully.'.'</br>';
    }
    else
    {
        echo 'Record insertion failed ! ';
    }
 
    //Closingthe connection
    mysql_close($con);
?>
Output:

Inserting Record in MySQL database Table using PHP



Updated 04-Mar-2020
I am a content writter !

Leave Comment

Comments

Liked By