Insert Data into MySQL 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.


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.

While doing data insert its best practice to use function get_magic_quotes_gpc() to check if current configuration for magic quote is set or not. If this function returns false then use function addslashes() to add slashes before quotes.

Example

Try out this example by putting this code into add_employee.php, this will take input using HTML Form and then it will create records into database.


   
   
      Add New Record in MySQL Database
   
   
   
      
            
               
Employee Name
Employee Address
Employee Salary
   
 
php_and_mysql.htm
Advertisements