PHP, form validation, isset() problem

Soldato
Joined
20 Oct 2002
Posts
6,212
Location
UK
Im creating a web form for user input into a database using PHP...

i have the form and have assigned:

$name = $_POST["name"];

im then trying to validate it using:

function CheckName($name)
{
if(isset($name))
{
if(!preg_match("/[^a-zA-Z\.\ ]+$/s",$name))
return TRUE;
else
return FALSE;
}
}

but i have the problem that the system thinks the variable $name is set, even when i load the page for the first time... or just press the submit button on the form without typing anything in it.

Im not sure whats going on, can anybody shed some light?
 
yeh the attribute in the form is called name

the assigning on the variable works... i have it outputting at the bottom of the page just as confirmation to the user....

/me pastes

The data you entered was correct, thank you!
Your Name : Matthew
Your Address : 161 xxxxxx Road
Your Postcode : xxx xxx
Your Telephone : 0115 xxxxxxx
Your Email : [email protected]
 
ok sorted it, now using

if(!empty($name))

i looked up isset and a user footnote at the bottom said that isset doesnt check the contents of the varaible, just that it is set (exists)
 
Back
Top Bottom