[PHP] Form validation

I want to warn users if the name and email field are invalid only if something has been entered. I used the code below. For some reason, the error message is always shown even when I put in a valid name and email.


// validate whether name has both last and first name
if($name && !preg_match("$name", " "))
	$nameStatus1 = "<br />*Include both first and last name";
			
// validate email's form
if($email && (!preg_match("$email", "@") || !preg_match("$email", ".")))
	$emailStatus1 = "<br />*Invalid";

Also, another problem: everything but the file input can remember what was previously written in it. So when I need to display an error message, the page reloads, and the user’s previous file upload location is gone.


<input name=\"design\" value=\"$design\" type=\"file\" size=\"50\" maxlength=\"100\" />