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 Link to comment https://forums.phpfreaks.com/topic/93065-a-little-help-here-with-my-if-statement/ 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 [email protected] its not going to catch [email protected]. Link to comment https://forums.phpfreaks.com/topic/93065-a-little-help-here-with-my-if-statement/#findComment-476810 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 :'( Link to comment https://forums.phpfreaks.com/topic/93065-a-little-help-here-with-my-if-statement/#findComment-476811 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. Link to comment https://forums.phpfreaks.com/topic/93065-a-little-help-here-with-my-if-statement/#findComment-476812 Share on other sites More sharing options...
youonly Posted February 26, 2008 Author Share Posted February 26, 2008 :'( awts ... Link to comment https://forums.phpfreaks.com/topic/93065-a-little-help-here-with-my-if-statement/#findComment-476814 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 Link to comment https://forums.phpfreaks.com/topic/93065-a-little-help-here-with-my-if-statement/#findComment-476816 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.