Jump to content

validate input


2wasted

Recommended Posts

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
Link to comment
https://forums.phpfreaks.com/topic/22919-validate-input/
Share on other sites

[code]<?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();
  }
}
?>[/code]
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));
Link to comment
https://forums.phpfreaks.com/topic/22919-validate-input/#findComment-103397
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.