• support@answerspoint.com

Inserting Data into a MySQL Database.

432

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

Your Answer

    Facebook Share