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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.