Home > DeveloperSection > Beginner > Inserting Record in MySQL database Table using PHP

Inserting Record in MySQL database Table using PHP


PHP PHP 
Ratings:
0 Comment(s)
 3347  View(s)
Rate this:

Inserting Record in MySQL database Table using PHP

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


Don't want to miss updates? Please click the below button!

Follow MindStick