Web Analytics Made Easy -
StatCounter Mail script not working - CodingForum

Announcement

Collapse
No announcement yet.

Mail script not working

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mail script not working

    Hi.I am trying to modify this mail script i have with the code below.Problem is that it still registers the mail in the db even though my if statement is there.
    PHP Code:
    function insert_mail() {
        if(!empty(
    $_POST['fname'])){
        
    $fname $_POST['fname'];
        }else{
        
    $fname NULL;
        echo 
    '<p>Please enter your first name</p>';//set up to check if first name was added
        
    }
        if(!empty(
    $_POST['lname'])){
        
    $lname $_POST['lname'];
        }else{
        
    $lname NULL;
        echo 
    '<p>Please enter your last name</p>';//set up to check if last name was added
        
    }
        
    $email $_POST['email'];

        if(
    $fname && $lname){
        
    $sql2="select * from mail where email='$email'";
        
    $result2=mysql_query($sql2) or die("select  fails");
        
    $no=mysql_num_rows($result2);
        }else{
        echo 
    'Please fill out the form completely';
        }
    // I thought by using this if statement this code would not be executed but
    // it adds it and echo's please enter your first name,please enter your last 
    //name and also echo's email added to list then the listname,It adds the e-//mail to 
    //the list anyways
        
        



        
    if ($no==0) {


            
    $sql "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')";
            
    $result mysql_query($sql) or die("insert fails");

            echo 
    "Email added to list: " LISTNAME;

        } else {

            echo 
    "Email Address Already Exists in List: " LISTNAME;

        } 
    This is my first post here I'm a newbie at php.So I appreciate any help.

  • #2
    You should be using isset
    PHP Code:
    if(isset($fname) && isset($lname)){ 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

    Comment


    • #3
      Hmm

      I tried to use the isset function and I still get the same results.

      Comment


      • #4
        Okay check to see if those two values are not equal to ''
        PHP Code:
        if($fname != '' && $lname != ''){ 
        ||||If you are getting paid to do a job, don't ask for help on it!||||

        Comment


        • #5
          K

          Here is what I did.
          PHP Code:
          function insert_mail() {
              if(!empty(
          $_POST['fname'])){
              
          $fname $_POST['fname'];
               }else{
              
          $fname NULL;
               echo 
          '<p>Please enter your first name</p>';
              }
              if(!empty(
          $_POST['lname'])){
              
          $lname $_POST['lname'];
              }else{
              
          $lname NULL;
              echo 
          '<p>Please enter your last name</p>';
              }
              
          $email $_POST['email'];

              if(
          $fname != '' && $lname != ''){
              
          $sql2="select * from mail where email='$email'";
              
          $result2=mysql_query($sql2) or die("select  fails");
              
          $no=mysql_num_rows($result2);
              }else{
              echo 
          'Please fill out the form completely';
              }
              
              



              if (
          $no==0) {


                  
          $sql "insert into mail(id,fname,lname,email) values(NULL,'$fname','$lname','$email')";  
                  
          $result mysql_query($sql) or die("insert fails");

                  echo 
          "Email added to list: " LISTNAME;//this gets run for some reason

              
          } else {

                  echo 
          "Email Address Already Exists in List: " LISTNAME;

              }




          this is in my config.php I have an index php.
          PHP Code:
          require('inc/config.php');
          include(
          'inc/form.php');

              if (
          $_SERVER['REQUEST_METHOD'] == "POST") {

                  
          insert_mail();//this goes to the mail fucntion in my include congig.php

              

          and my form.php which is the html form
          PHP Code:
          <form action='<? echo BASEHREF?>index.php' method=post>

          <TABLE BORDER=0 ALIGN=center>
              <TR>

                  <TD>first name</TD>
                  <TD><INPUT TYPE=text name=fname></TD>

              </TR>


              <TR>
                  <TD>last name</TD>
                  <TD><INPUT TYPE=text name=lname></TD>
              </TR>

              <TR>
                  <TD>email</tD>
                  <TD><INPUT TYPE=text name=email></td>
              </tR>

              <TR>
                  <TD colspan=2 align=center><INPUT TYPE=submit value=join> <INPUT TYPE=reset value=reset><BR></TD>
              </tR>

          </TABLE>


          </FORM>

          </center>

          Comment

          Working...
          X