2wasted Posted October 3, 2006 Share Posted October 3, 2006 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 helpCharlie Quote Link to comment Share on other sites More sharing options...
thepip3r Posted October 3, 2006 Share Posted October 3, 2006 just change your error checking to [code]if (!$_POST['email']) { echo "error, no email addy"; exit;}[/code]u need to also do a much more thorough check on an email address using preg_match() or something like that. Quote Link to comment Share on other sites More sharing options...
2wasted Posted October 3, 2006 Author Share Posted October 3, 2006 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..cheersCharlie Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 3, 2006 Share Posted October 3, 2006 [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 emailif ($_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 checl1. if the email is blank2. if it's formatted correctly3. if it's dns(domain name), is real or not(not 100% accurate, but effective nonetheless)); Quote Link to comment Share on other sites More sharing options...
2wasted Posted October 3, 2006 Author Share Posted October 3, 2006 thx alot m8Charlie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.