If you see just the PHP code you probably forgot the opening PHP tag before you start to write actual PHP code.
<?php
$dbc = mysqli_connect('localhost', 'root', 'password', 'leadmen')
or die('Error connection to MySQL server.');
$first_name = $_POST['firstname'];
$last_name = $_POST['lastname'];
$email = $_POST['email'];
$query ="INSERT INTO leadmen_usernames (first_name, last_name, email)" .
"VALUES ('$first_name', '$last_name', '$email')";
mysqli_query($dbc, $query)
or die('Error querying database');
echo 'Username Added.';
mysqli_close($dbc);
?>
You can close it again with '?>'