Jump to content


Photo

validate input


  • Please log in to reply
4 replies to this topic

#1 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 03 October 2006 - 08:52 PM

lo all,
i have a simple form that posts fine 2 a mysql, but i want to check that there is something in the email textbox. So i did this...
//validate email
$var = $_POST['email'];
$len = strlen($var);
if($len >0)
{
$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query')";
mysql_query($query);

mysql_close();
}
else
{
echo "Error:Please fill in your email address";
}
?>
its does not work:-(
thx for any help
Charlie

#2 thepip3r

thepip3r
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts

Posted 03 October 2006 - 09:01 PM

just change your error checking to

if (!$_POST['email']) {
  echo "error, no email addy";
  exit;
}

u need to also do a much more thorough check on an email address using preg_match() or something like that.

#3 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 03 October 2006 - 09:08 PM

do i just put in ur bit of code instead of the stuff i done??
i tryed that and the error was on the page on load..
cheers
Charlie

#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 03 October 2006 - 09:17 PM

<?php
//validate email
// setup errorhandler
$errorhandler = "";
// setup email check
$regexemail = 
"^[A-Za-z0-9\._-]+@([A-Za-z0-9][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";
// validation on email
if ($_POST['email'] == "") {
$errorhandler .= "Email was left blank";
}
if (!ereg("$regexemail", $email)) { 
	$errorhandler .= "The email address is improperly formatted<br />";
}
if(!(getmxrr(substr(strstr($email, '@'), 1), $temp)) || checkdnsrr(gethostbyname(substr(strstr($email, '@'), 1)), "ANY")) {
	$errorhandler .= "The Domain name for the email address does not exist<br />";
}
if ($errorhandler != "") {
echo "<span style=\"color:red;\">";
echo $errorhandler;
echo "</span>";
}
if ($errorhandler == "") {
$var = mysql_real_escape_string($_POST['email']);
$len = strlen($var);
if ($len >0) {
$query = "INSERT INTO onlineform VALUES ('','$name','$Cname','$email','$Query')";
mysql_query($query);

mysql_close();
  }
}
?>
That will checl
1. if the email is blank
2. if it's formatted correctly
3. if it's dns(domain name), is real or not(not 100% accurate, but effective nonetheless));

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 2wasted

2wasted
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 03 October 2006 - 09:21 PM

thx alot m8
Charlie




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users