Tuesday, 20 February 2018

Insert Record in Mysql Database using PHP

Insert statement:
Insert statement is used to insert data into table in MySQL
Syntax: 
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
Example:
INSERT INTO emp(id,name,salary)values(101,"Dipak",45500.78);

Example:
<?php
$servername= 'localhost’;
$username = 'root';
$password = '';
$dbname='lp'
$con = mysqli_connect($servername, $username, $password,$dbname);
if(! $con )
{
  die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';

$sql ='INSERT  INTO  emp(id,name,salary)values(101,"Dipak",45500.78)'; 

if(mysqli_query($con, $sql)){ 
 echo "Record inserted successfully"; 
}
else{ 
echo "Could not insert record: ". mysqli_error($con); 
}  

mysqli_close($con);
?>
Output:
Connected successfully
Record inserted successfully

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...