php mysql insert data in database
user insert data in mysql query way to insert data in database.Data can be entered into MySQL tables by executing SQL INSERT statement through PHP function mysql_query. Below a simple example to insert a record into employee table.
Example
Try out following example to insert record into employee table.
<?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = 'INSERT INTO student '. '(stu_name,stu_address, stu_mark, join_date) '. 'VALUES ( "sam", "india", 99, NOW() )'; mysql_select_db('test_db'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfully\n"; mysql_close($conn); ?>
In real application, all the values will be taken using HTML form and then those values will be captured using PHP script and finally they will be inserted into MySQL tables.
the Function insert data's in database.