Try this, if you want to use a PHP only solution to your problem.
<?php
function submit_form(){
$host = "localhost";
$user = "user";
$password = "password";
$database = "database";
$firstname = filter_var($_POST['firstname'], FILTER_SANITIZE_STRING);
$lastname = filter_var($_POST['lastname'], FILTER_SANITIZE_STRING);
$email = filter_var(filter_var($_POST['email'],FILTER_SANITIZE_EMAIL),FILTER_VALIDATE_EMAIL);
// open connection to database
$link = mysqli_connect($host, $user, $password, $database);
IF (!$link){
echo ("Unable to connect to database!");
}
ELSE {
//INSERT VALUES INTO DATABASE
$query = "INSERT INTO users (firstname,lastname,email)
VALUES('".$firstname."', '".$lastname."', '".$email."'";
return mysqli_query($link,$query);
}
//close connection to database
mysqli_close($link);
}
$form = <<<EODuserform
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Form</title>
</head>
<form action="{$_SERVER['PHP_SELF']}" method="POST" name="userform">
<label for='first'>First Name:</label></br>
<input type="text" name="firstname" id="first" maxlength="25" tabindex='1' VALUE="firstname" /></br>
<label for='first'>Last Name:</label></br>
<input type="text" name="lastname" id='lastname' maxlength="25" tabindex='2' VALUE="lastname" /></br>
<label for='email'>E-mail:</label></br>
<input type="text" name="email" id='email' maxlength="100" tabindex='3' VALUE="email" /></br>
<input type="submit" class='button' name="submit" value="submit" tabindex='4' />
</form>
</body>
</html>
EODuserform;
IF(!IsSet($_POST['submit'])){ // Check if form is not send, if not display empty form.
echo $form;
}
ELSE{
// in the case you want to send something to the database use
submit_form();
echo ('Thanks for submitting your form');
}
?>
It is a very basic script you can find a similar script on this page: Form not saving to database