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