youonly Posted February 26, 2008 Share Posted February 26, 2008 <? function insert () { if ($_POST['btnSubmit'] == "Submit") { $valid = true; if (eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$', $_POST["txtemail"])) $valid=true; else { $valid=false; echo "<font color='#0000FF' size='3' face='Verdana'>INVALID EMAIL</font>"; } $sql2 = mysql_query("SELECT * FROM tblnews WHERE emailadd = '".$_POST['txtemail']."'"); if (mysql_num_rows($sql2) > 0) { echo "<font color='#0000FF' size='3' face='Verdana'>EMAIL ALREADY REGISTERED</font>"; $valid=false; } if($valid){ $SQL = "INSERT INTO tblnews (cmpname,name,emailadd,contactnum,address) VALUES ('".$_POST['txtcmpname']."', '".$_POST['txtaddress']."', '".$_POST['txtemail']."', '".$_POST['txtcontact']."', '".$_POST['txtname']."')"; mysql_query($SQL); echo "<font color='#0000FF' size='3' face='Verdana'>Thank for subscribing</font>"; } } ?> this is an insert function wherein if the email add is already exist it will not add the data,, the same with if the email is not valid (no @ and . chars), and if some fields are not filled it will also not perform the insert query .. im having a difficult time trapping it.. this code still add the data even though the email entered is not valid kindly help pls thnx in advace Quote Link to comment Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 everything seems to be ok. I would do a strtolower on the email as well because if its in a diffrent context like if its in the db as Blah@Blah.com its not going to catch blah@blah.com. Quote Link to comment Share on other sites More sharing options...
youonly Posted February 26, 2008 Author Share Posted February 26, 2008 ummm nop its not ok ??? whenever i enter an invalid email it still execute the insert query :'( Quote Link to comment Share on other sites More sharing options...
vicodin Posted February 26, 2008 Share Posted February 26, 2008 Oh...Google it... you will find tons of valid email address scripts. Just incorporate it. Quote Link to comment Share on other sites More sharing options...
youonly Posted February 26, 2008 Author Share Posted February 26, 2008 :'( awts ... Quote Link to comment Share on other sites More sharing options...
DarkerAngel Posted February 26, 2008 Share Posted February 26, 2008 if (preg_match('/^([a-z0-9._-](\+[a-z0-9])*)+@[a-z0-9.-]+\.[a-z]{2,6}$/i', $_POST["txtemail"])) { try that one 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.