MySQL - insert into

MySQL - insert into statement is used to insert new records in a table. Insert query doesn't have WHERE clause.

MYSQL Syntax :

INSERT INTO table_name (column1, column2, column3, column4, .....) VALUES (value1, value2, value3,  value4 .....);

PHP SCRIPT :
You can insert new records into table using php code as per as below.

<?php
$hostname="localhost";
$username="root";
$password="********";
$link= mysqli_connect($hostname, $username, $password);
mysqli_select_db($link,DATABASE);
$returnval = mysqli_query($link,"INSERT INTO tblstudent (stud_id, stud_name, stud_mobile, stud_address, Stud_birthdate) VALUES (1, 'manoj patel', '9428982251', 'ahmedabad', '2000-04-16')");

$id=mysqli_insert_id($link);
if($returnval ){
        echo "New row is inserted successfully for row id :".$id;
}else{
       die('MySQL Error : ' . mysqli_error($link));
}
mysqli_close($link);

?>
 

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

75366