Jump to content

a little help here with my if statement..


youonly

Recommended Posts

<?

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

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.