connection.inc.php
code:
<?php
function opendb(){
mysql_connect("localhost", "username", "password") or die("Can't Connect to database, try again later");
mysql_select_db("database");
}
?>
index.php
code:
<?
include("connection.inc.php");
opendb();
$sql = "INSERT INTO `table` (`id`, `name`) VALUES ('".$id."', '".$name."')";
mysql_query($sql) or die (mysql_error());
?>
That's how I always do it with my websites.
EDIT: Added the mysql_query bit.