• support@answerspoint.com

Inserting Data into a MySQL Database.

1997

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 7 years ago
  • Community  wiki

Your Answer

    Facebook Share        
       
  • asked 7 years ago
  • viewed 1997 times
  • active 7 years ago

Best Rated Questions