Thread: Form Validation
View Single Post
Old Feb 27th, 2006, 9:45 AM   #1
TecBrain
Hobbyist Programmer
 
Join Date: Sep 2004
Location: Cyprus
Posts: 147
Rep Power: 5 TecBrain is on a distinguished road
Form Validation

Am trying to check whether the input is text or not, so what i did is creating a function and return the value false or true, is this legal, if no then how can i go around this problem.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) 
{
	$countryname= $_POST['countryname'];
	$currency = $_POST['currency'];
	$image = $fileName = $_FILES['uploaded']['name'];
	
	function isLetters($countryname) 
	{
  	return !preg_match ('/[^A-z]/', $countryname);
	}
	
	isLetters($countryname);
	
	if ((is_float($currency)) || (!$countryname))
	{
		echo "error";
		exit();
	}
	else if (empty($countryname) || empty($currency))
	{
		echo "error2";
		exit();
	}
	
	else
	{
	$query = "INSERT INTO countries (countryname, currency, imgpath) VALUES ('$countryname', '$currency', '$image')";
	mysql_select_db($database, $dbcnx);
	mysql_query($query) or die('Error, insert query failed');
	}
}
__________________
Personal Portfolio
TecBrain Support Forum
Linux VS Windows ... Dont Even Think of it ..
Distribution: Slackware
if (OS==Linux) return success
There are 10 kinds of people, those who can read binary numbers and those who can't.
TecBrain is offline   Reply With Quote