Adding a Row to a Table : mysql_query « MySQL Database « PHP






Adding a Row to a Table

 
<html>
<head>
<title>Adding a Row to a Database</title>
</head>
<body>
<div>
<?php
$user = "root";
$pass = "";
$db = "mydatabase";
$link = @mysql_connect( "localhost", $user, $pass );
if ( ! $link ) {
  die( "Couldn't connect to MySQL: ".mysql_error() );
}
print "<h2>Successfully connected to server</h2>\n\n";
@mysql_select_db( $db ) or die ( "Couldn't open $db: ".mysql_error() );
print "Successfully selected database \"$db\"<br />\n";

$query = "INSERT INTO domains( domain, sex, mail )values( 'example.com', 'F', 'a@example.com' )";
print "running query: <br />\n$query<br />\n";
mysql_query( $query, $link ) or die ( "INSERT error: ".mysql_error() );
mysql_close( $link );
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.Add record to my_database/my_table
2.Deleting Data
3.Get data from mysql
4.mysql_query.php
5.function mysql_query() queries the database.
6.Storing Information in a Database
7.Using PHP variables wherever you want inside SQL queries
8.Sign the guestbook