• support@answerspoint.com

Inserting Data into a MySQL Database.

1912

Data can be entered into MySQL tables by executing SQL INSERT INTO statement through PHP function mysql_query().

 

1Answer


0

Data can be entered into MySQL tables by executing SQL INSERT INTO statement through PHP function mysql_query().

<html>
<head>
<title>Inserting Data into a MySQL Database.</title>
</head>

<body>
	<?php
       $servername = "localhost";
        $username = "root";
        $password = "";
        
        // Create connection
        $conn = mysql_connect($servername, $username, $password);
       
       if(! $conn ) {
          die('Could not connect: ' . mysql_error());
       }
       
       $sql = 'INSERT INTO my_table' . '(firstname, lastname, email, reg_date)'.
        'VALUES ("Roji", "Doyal", "roji@example.com", "NOW()")';
        
       mysql_select_db('my_database');
       $result = mysql_query( $sql, $conn );
       
       if(! $result ) {
          die('Could not enter data: ' . mysql_error());
       }
       
       echo "Entered data successfully";
       
       mysql_close($conn);
    ?>
</body>
</html>

 

  • answered 6 years ago
  • Community  wiki

Your Answer

    Facebook Share        
       
  • asked 6 years ago
  • viewed 1912 times
  • active 6 years ago

Best Rated Questions