Попробуйте следующее
first Установите форму действия в файл php (index.php) .
<form method="Post" action="form.php">
<fieldset class="form-group">
<label for="label">Username</label>
<input type="text" class="form-control" name="username" >
</fieldset>
<fieldset class="form-group">
<label for="f">Lastname</label>
<input type="text" class="form-control" name="lastname" >
</fieldset>
<button type="button" name="submit" class="btn btn-primary">Submit</button>
form.php это будет вторая страница
<?php
$server="localhost";
$username ="root";
$password ="";
$database ="you_database";
$connection =mysqli_connect($server ,$username ,$password,$database); //start connection
if ($connection==TRUE) // test connection
{
echo "connected succefull";
}
if (isset($_POST['submit'])) //test submit name in form
{
// declare parameter to initialized in text fild in form
// and those fild should appear in serve (apache mysql)
$username =$_POST['username'];
$lastname =$_POST['lastname'];
$query ="INSERT INTO your_table VALUES(NULL, '$username' ,'$lastname' ");
$result =mysqli_query($connection ,$query);
if ($result == TRUE) {
echo "data insert succefull";
}else{
echo "failed to insert";
}
}
mysqli_error($connection);
?>