Inserting data into a table is also same as table and database creation. Create the MySQL query for inserting data into a table and then execute it with mysql_query() function. Data can be inserted into the database tables by using SQL INSERT statement.

Syntax for MySQL statement of INSERT

INSERT INTO table_name (column1, column, column3, column4)VALUES ("value1", "value2", "value3", "value4")

Below is an example of inserting data into table

$database_host = 'localhost:3036';
$database_user = 'root';
$database_pass = '';
$conn = mysql_connect($database_host, $database_user, $database_pass);
if(! $conn ) {
   die('Could not connect: ' . mysql_error());
   echo 'Connected successfully\n';
$selected_or_not = mysql_select_db( 'xyz_school' );
if(! $selected_or_not ) {
   die('Not Selected xyz_school database');
   echo 'Selected xyz_school database';
$sql = 'INSERT INTO student '.'(student_name,student_address, student_enrollment_no, join_date) '.'VALUES ( "Dummy Student", "XYZ", 2018, NOW() )';
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
  die('Could not insert into table: ' . mysql_error());
echo "Inserted successfully\n";

Find us on

Facebook Google Plus Twitter Pinterest YouTube

web hit counter