hello

Tuesday, September 23, 2014

3.1 Insert

1) Connection


       
//Connection variables -->START

$host = 'localhost';    /*domain name or host path*/
$user = 'root';         /*database username*/
$pass = 'your_db_pass'; /*database password*/ 
$database = 'db_users';    /*database name*/

//Connection variables-->END

2) Connection to Database

       
/*Create a connection to database*/
$connection = mysql_connect($host, $user, $pass) or die('Connection Failed');

/*Selecting the database based on suplied connection*/
$select_db = mysql_select_db($database, $connection) or die('Connection DB Failed');


3)The Query

       
/*Make a Query INSERT*/
$query = "insert into users_tbl (username, password) values('hac101', 'pass123')";

4) Full Code

       
/*Connection variables -->START*/

$host = 'localhost';    /*domain name or host path*/
$user = 'root';         /*database username*/
$pass = 'your_db_pass'; /*database password*/ 
$database = 'db_users';    /*database name*/

//Connection variables-->END

/*Create a connection to database*/
$connection = mysql_connect($host, $user, $pass) or die('Connection Failed');

/*Selecting the database based on suplied connection*/
$select_db = mysql_select_db($database, $connection) or die('Connection DB Failed');

/*Make a Query INSERT*/
$query = "insert into users_tbl (username, password) values('hac101', 'pass123')";

/*Run the Query*/
$result = mysql_query($query) or die("Query Failed");      
 

No comments: