PHP Code:
<html>
<head></head>
<body>
.................
<?php
function write_in_db() {
$servername = 'localhost';
$username = 'cpanel_username';
$password 'password';
$database = "your_db_name";
$db_connection = mysql_connect($servername, $username, $password)
or die ("Unable to connect to the DB Server!");
mysql_select_db($database) or die ("Can't select database!");
$query = 'INSERT INTO `contacts` '.
'(
`firstname`,
`lastname`
) VALUES (
\'' . $_POST['firstname'] . '\',
\'' . $_POST['lastname'] . '\'
);';
// execute query
$result = mysql_query($query) or die ("Error in query: $query. <br>".mysql_error());
return "inserted ".$_POST['firstname']." and his info into 'contacts'";
}
?>
...............
<?php if(isset($_POST['s_save'])) { echo write_in_db(); } ?>
<form ........ method="post"
some form fields
<input type="submit" name="s_save" value="save">
</form>
...........................
</body>
</html>