Page 1 of 2

email validation error

Posted: Thu Apr 02, 2009 7:19 am
by angelic_devil
i m trying to validate the email address before entering into the database ....
problem....its giving error in emailid field irrespective of whether id is right or wrong.
this is wat i created...plz help ...and when u make corrections plz highlight wat u added n wat u removed in different colors so i can easily understand...thanx i m getting the error as follows

Notice: Undefined variable: emailid in D:\wamp\www\php_stockphotos\new_user.php on line 35

Warning: ereg() [function.ereg]: REG_BADRPT in D:\wamp\www\php_stockphotos\new_user.php on line 35


line no 3. is line no. 35 in the following

add_user.php

Code: Select all

if ( empty($errors) )
        {
            if ( ereg ($pattern,$emailid))
            {
                
                  $query = "INSERT INTO users (username, hashed_password, emailid
                        ) 
                        VALUES ('{$username}', '{$hashed_password}', '{$emailid}'
                        )";
                  $result = mysql_query($query, $connection);
                if ($result) {
                    $message = "Request for your account has been sent to the admin...wait for ";
                    $message .= "email confirmation";
                    $username = "";
                    $password = "";
                    $emailid = "";
                    redirect_to('basic.php');
                        }       
                else {
                    $message = "The user could not be created.";
                    }
            }
            else 
            { 
                    $message = "Enter a valid email address";
            }
                
        
        
        else 
        {
            if (count($errors) == 1) {
                $message = "There was 1 error in the form.";
                
            } else {
                $message = "There were " . count($errors) . " errors in the form.";
                
            }
        }

Re: email validation error

Posted: Thu Apr 02, 2009 7:20 am
by angelic_devil
ok

Re: email validation error

Posted: Thu Apr 02, 2009 7:20 am
by angelic_devil
form_functions.php

Code: Select all

<?php
function display_errors($error_array) {
    echo "<p class=\"errors\">";
    echo "Please review the following fields:<br />";
    foreach($error_array as $error) {
        echo " - " . $error . "<br />";
    }
    echo "</p>";
 
?>

Re: email validation error

Posted: Thu Apr 02, 2009 7:22 am
by angelic_devil

Code: Select all

<?
function mysql_prep( $value ) {
        $magic_quotes_active = get_magic_quotes_gpc();
        $new_enough_php = function_exists( "mysql_real_escape_string" ); // i.e. PHP >= v4.3.0
        if( $new_enough_php ) { // PHP v4.3.0 or higher
            // undo any magic quote effects so mysql_real_escape_string can do the work
            if( $magic_quotes_active ) { $value = stripslashes( $value ); }
            $value = mysql_real_escape_string( $value );
        } else { // before PHP v4.3.0
            // if magic quotes aren't already on then add slashes manually
            if( !$magic_quotes_active ) { $value = addslashes( $value ); }
            // if magic quotes are active, then the slashes already exist
        }
        return $value;
    }
 
function redirect_to( $location = NULL ) {
        if ($location != NULL) {
            header("Location: {$location}");
            exit;
        }
    }
 
    function confirm_query($result_set) {
        if (!$result_set) {
            die("Database query failed: " . mysql_error());
        }
    }
?>

Re: email validation error

Posted: Thu Apr 02, 2009 4:10 pm
by RobertGonzalez
Are you just checking the format of a valid email address? If so, why not hit up regexplib.com and look at the many variations they offer there.

Re: email validation error

Posted: Thu Apr 02, 2009 4:15 pm
by angelic_devil
i already used tht reg exp in the check_email.php mentioned still gettitng the error

Re: email validation error

Posted: Thu Apr 02, 2009 4:32 pm
by RobertGonzalez
Have you tried using preg_match instead of the ereg functions?

If you read the manual on preg_match ( http://php.net/preg_match ) and read through the user comments you might get to this:
http://us2.php.net/manual/en/function.p ... .php#88007

See if that can help you.

Re: email validation error

Posted: Thu Apr 02, 2009 5:09 pm
by angelic_devil
now its accepting all its not checking the validity of email

Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hashed_password ='028298f9uhh9urh' LIMIT 1' at line 1

Re: email validation error

Posted: Fri Apr 03, 2009 12:58 pm
by RobertGonzalez
Can you post a sample email address you are sending that function?

Re: email validation error

Posted: Fri Apr 03, 2009 5:55 pm
by angelic_devil
its accepting both

1.god@god.com

2.nouse

Re: email validation error

Posted: Fri Apr 03, 2009 6:48 pm
by RobertGonzalez

Re: email validation error

Posted: Fri Apr 03, 2009 7:38 pm
by angelic_devil
so shud i put this in $pattern...is the rest of function ok?

^(?:(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|\x5c(?=[@,"\[\]\x5c\x00-\x20\x7f-\xff]))(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]\x5c\x00-\x20\x7f-\xff]|\x5c(?=[@,"\[\]\x5c\x00-\x20\x7f-\xff])|\.(?=[^\.])){1,62}(?:[^@,"\[\]\x5c\x00-\x20\x7f-\xff\.]|(?<=\x5c)[@,"\[\]\x5c\x00-\x20\x7f-\xff])|"(?:[^"]|(?<=\x5c)"){1,62}")@(?:(?:[a-z0-9][a-z0-9-]{1,61}[a-z0-9]\.?)+\.[a-z]{2,6}|\[(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])(?:\.(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])){3}\])$

Re: email validation error

Posted: Fri Apr 03, 2009 11:25 pm
by RobertGonzalez
Have you tried it yet? It is ok to try it out and see if it works.

Re: email validation error

Posted: Fri Apr 03, 2009 11:45 pm
by Benjamin
@Everah, can you add code tags to the first several posts please?

Re: email validation error

Posted: Sat Apr 04, 2009 11:24 am
by RobertGonzalez
astions wrote:@Everah, can you add code tags to the first several posts please?
Done