在以php格式提交之前出现错误

I have the following code but unfortunately $error appears as soon as the page loads, before clicking on submit. What am I doing wrong?

(filename= form.php)

<?php
$error="";
if (isset($_POST['submit']) && $_POST['submit'] == "Submit") {  

$name = $_POST['name'];
$email = $_POST['email'];

if($name=="" || $email==""){
$error .= "Error: all fields are required";
}
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email)) {
$error .= "<br/> Error: Invalid email address";
}

if (isset($error) && ($error!=="")) {
    echo $error;
}
elseif (empty($error)){
    // this works no need to write here... send form.
    }
    }

echo<<<_END
<html><head><body>
<form method='post' action='form.php'>
<p>Name</p> <input type="text" name="name" value='$name'>
<p>Email</p> <input type="text" name="email" value='$email'>
<input type="submit" name="submit" value="Submit">
<input type="reset" name="reset" value="Clear">
</form>
</body>
</html>
_END;
?>
if (isset($error) && (!$error=="")) {
echo $error;

}

if $error is set and $error equals nothing echo $error? $error is being set when you intialize it to "" in the first line and it is equal to ""

Just noticed the ! in the second part of the if. Do what the person below me said.

Replace (!$error=="")) with ($error!=="")).