My question is too long winded to find an answer. Please excuse me. Maybe I just don't know how to abbreviate my question. Well here is the problem and and the question. See the code below:
<?php
if(isset($_POST['submit'])) {
$name = $_POST['name'];
$email = $_POST['email'];
$server = mysqli_connect('localhost', 'root', '', 'newsletter') or die("The Server Cannot Be Reached at this Time!");
//$dbc = mysqli_select_db($server, 'newsletter') or die("There is a problem accessing the databse!");
$query = mysqli_query($server, "INSERT INTO subscribers (name, email) VALUES('$name','$email')");
$name = strip_tags($name);
$email = strip_tags($email);
if(empty($name) || empty($email)) {
echo "All Fields Must Be Filled In!";
} else {
echo "You have been successfully subscribed";
}
}
mysqli_close($server);
?>
This code works. It gets the information to the database when the user fills out the form. What I noticed is that when the user only fills in one field, i.e. name and leaves the email field empty the if statement returns the line "All Fields Must Be Filled In". Then you return to the page and fill in the email field and everything is fine. But when I check the database I notice that there is an insertion of an id and name for the attempt where the email was not filled out on the form. Is this normal? Or what am I doing wrong. Thanks