Results 1 to 5 of 5

Thread: newsletter subscribe form - always invalid - regexp

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default newsletter subscribe form - always invalid - regexp

    http://www.poliscarhire.com/index.php
    Email address (Newsletter Subscribute) always invalid at above, I use both reg exp below (first=current, 18july2008) but always invalid like the info@poliscarhire.com ?
    what about addresses like : xxx@yyy.com.cy

    reg exp
    (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z\.]{2,4}", $email))
    (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))

    code(current, 18july2008)
    Code:
    <?php
    $email = $_POST['email'];
    
    include("../dbinfo.php");
    $linkid = @mysql_connect($hostname,$username,$password) or die( "Unable to connect to Database Server. Please try again later.");  
    @mysql_select_db($database,$linkid) or die( "Unable to select database.  Please try again later,");   // @
    
    if ($_POST['unsubscribute']) {
      $query = "SELECT * FROM $NewslettersTable";   
      $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
      $count = @mysql_num_rows($result); 
      for ($j=0;$j<$count;$j++) {
         $row = mysql_fetch_row($result);
         if ($email != $row['email']) {
              echo "This email address does NOT exist, in the database !";
              break;
         }
         $query = "DELETE FROM $NewslettersTable WHERE email='$email'";   
         $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
         echo "You have successfully UnSubscribute from our 'Newsletter (Latest Offers)' as: \n". $email; 
      } 
    }
    else {
     if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z\.]{2,4}", $email)) {  // "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
      $query = "SELECT * FROM $NewslettersTable";   
      $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
      $count = @mysql_num_rows($result); 
      for ($j=0;$j<$count;$j++) {
         $row = mysql_fetch_row($result);
         if ($email == $row['email']) {
              echo "This email address already exist, in the database !";
              break;
         }
    	 // mysql_free_result($result);
         $query = "INSERT INTO $NewslettersTable VALUES(NULL,'$email')";   
         $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
         echo "You have successfully Subscribute to our 'Newsletter (Latest Offers)' as: \n". $email; 
      } // end for
     } else {   
        echo "InValid email address. Please retry !";
     }  // end if
    } // end if main
    // mysql_free_result($result);
    mysql_close($linkid);
    ?>

  2. #2
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    Please go to
    http://www.poliscarhire.com/index.php
    and try, it does appear the correct message , what is wrong in the php/mysql code ?

  3. #3
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    This doesn't look like a problem in MySQL this is a regex problem. You seem to be using a regular expression without knowing what it is intended to match. If you just want to match most email addresses try this regular expression
    PHP Code:
    preg_match("^.+@[a-zA-Z0-9_]+(.[a-zA-Z0-9])+",$email); 
    Untested by the way.

  4. #4
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    I found the error , was non correct refererence to html fields of email from php, but the error now is that what ever you write appears null(only title/heading appear) ?

    what about addresses like : xxx@yyy.com.cy or xxx@yyy.kk.jj.hh.edu.us how validate ?
    Code:
    <td align="center" valign="middle"><h1 class="text_normal15px">
              <?php
    $email = $_POST['email-news'];
    
    include("../dbinfo.php");
    $linkid = @mysql_connect($hostname,$username,$password) or die( "Unable to connect to Database Server. Please try again later.");  
    @mysql_select_db($database,$linkid) or die( "Unable to select database.  Please try again later,");   // @
    
    if ($_POST['unsubscribute']) {
      $query = "SELECT * FROM $NewslettersTable";   
      $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
      $count = @mysql_num_rows($result); 
      for ($j=0;$j<$count;$j++) {
         $row = mysql_fetch_row($result);
         if ($email != $row['email']) {
              echo "This email address does NOT exist, in the database !";
              break;
         }
         $query = "DELETE FROM $NewslettersTable WHERE email='$email'";   
         $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
         echo "You have successfully UnSubscribute from our 'Newsletter (Latest Offers)' as: \n". $email; 
      } 
    }
    else {
     if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z\.]{2,4}", $email)) {  // "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
      $query = "SELECT * FROM $NewslettersTable";   
      $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
      $count = @mysql_num_rows($result); 
      for ($j=0;$j<$count;$j++) {
         $row = mysql_fetch_row($result);
         if ($email == $row['email']) {
              echo "This email address already exist, in the database !";
              break;
         }
    	 // mysql_free_result($result);
         $query = "INSERT INTO $NewslettersTable VALUES(NULL,'$email')";   
         $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
         echo "You have successfully Subscribute to our 'Newsletter (Latest Offers)' as: \n". $email; 
      } // end for
     } else {   
        echo "InValid email address. Please retry !";
     }  // end if
    } // end if main
    // mysql_free_result($result);
    mysql_close($linkid);
    ?>
            </td>

  5. #5
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    I change script significantly now the only problem when I insert an email address and press "'subscribute" if it already exist in DB:
    DOES NOT APPEAR:
    "This email address ( $email ) already exist, in the database !"
    BUT APPEAR:
    ""You have successfully Subscribute to our 'Newsletter (Latest Offers)' as: \n". $email"
    well ?

    Code:
              <td align="center" valign="middle"><h1 class="text_normal15px">
              <?php
    $email = $_POST['email-news'];
    
    include("../dbinfo.php");
    $linkid = @mysql_connect($hostname,$username,$password) or die( "Unable to connect to Database Server. Please try again later.");  
    @mysql_select_db($database,$linkid) or die( "Unable to select database.  Please try again later,");   // @
    
    if ($_POST['unsubscribute']) {
    	  $query = "SELECT * FROM $NewslettersTable";   
    	  $result = @mysql_query($query,$linkid) or die("Unable to execute query. Please try again later.");  
    	  $count = @mysql_num_rows($result); 
    	  // echo $count;
    	  $f = "n";
    	  for ($j=0;$j<$count;$j++) {
    		 $row = mysql_fetch_row($result);
    		 if ($email == $row[1]) {  // "info2@poliscarhire.com"
    			  $f = "y";
    			  break;
    		 }
    	  } 
    	 if ($f != "y") {
    	 	echo "This email address ( $email ) does NOT exist, in the database !";
         } else {
    		 $query = "DELETE FROM $NewslettersTable WHERE email='$email'";   
    		 $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
    		 echo "You have successfully UnSubscribute from our 'Newsletter (Latest Offers)' as: \n". $email;
    	 } 
    }
    else {
     if (eregi("^[a-z0-9]+([-_\.]?[a-z0-9])+@[a-z0-9]+([-_\.]?[a-z0-9])+\.[a-z\.]{2,4}", $email)) {  // "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"
    	  $query = "SELECT * FROM $NewslettersTable";   
    	  $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
    	  $count = @mysql_num_rows($result); 
    	  $f2 = "n";
    	  if ($count > 0) {
    		  for ($j=0;$j<$count;$j++) {
    			 $row = mysql_fetch_row($result);
    			 if ($email == $row[1]) {  //  'email'
    				  echo "This email address ( $email ) already exist, in the database !";
    				  $f2 = "y";
    				  break;
    			 }
    		  } // end for
    	  }  // end if
    	  // mysql_free_result($result);
    	  if ($f2 == "n") {
    		  $query = "INSERT INTO $NewslettersTable VALUES(NULL,'$email')";   
    		  $result = @mysql_query($query,$linkid) or die( "Unable to execute query. Please try again later.");  
    		  echo "You have successfully Subscribute to our 'Newsletter (Latest Offers)' as: \n". $email; 
          }
     } else {   
    	echo "InValid email address. Please retry !";
     }  // end if
    } // end if main
    // mysql_free_result($result);
    mysql_close($linkid);
    ?></h1>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •