blesseld Posted September 1, 2009 Share Posted September 1, 2009 Hey, Ok , so i have my form working, and it checks to make sure the password and email fields match, and I just want to add an email verification function. I added this to my functions.php file <?php function is_valid_email($email) { $result = TRUE; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) { $result = FALSE; } return $result; } ?> First I edited it to be $var instead of $email simply because I have a $reemail variable as well for the retype email form field. So now it's... <?php function is_valid_email($var) { $result = TRUE; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $var)) { $result = FALSE; } return $result; } ?> And this is the main chunk of my signup.php *see commented line <?php if (isset($_SESSION['user'])) destroySession(); if (isset($_POST['user'])) { $user = sanitizeString($_POST['user']); $pass = sanitizeString($_POST['pass']); $repass = sanitizeString($_POST['repass']); $fname = sanitizeString($_POST['fname']); $lname = sanitizeString($_POST['lname']); $email = sanitizeString($_POST['email']); //this is what I originally had $reemail = sanitizeString($_POST['reemail']);//this is what I originally had $email = is_valid_email($_POST['email']); //this is what I tried $reemail = is_valid_email($_POST['reemail']);//tried removing the sanitize strings for email as well if ($user == "" || $pass == "" || $email == "") { $error = "<div id=\"warning-box\"><p class=\"main-text\">Not all fields were entered. Please ensure that you have entered:<br />- User Name<br />- Password<br />- Email<br /><br /></p></div><br />"; } elseif ($repass != $pass) { $error1 = "<div id=\"warning-box\"><p class=\"main-text\">Please ensure that you have entered:<br />- User Name<br />- Password<br />- Email<br /><br /><span style=\"color:#ff0000;\">Error</span>: The passwords entered do not match.<br /><br /></p></div><br />"; } elseif ($reemail != $email) { $error2 = "<div id=\"warning-box\"><p class=\"main-text\">Please ensure that you have entered:<br />- User Name<br />- Password<br />- Email<br /><br /><span style=\"color:#ff0000;\">Error</span>: The email addresses entered do not match.<br /><br /></p></div><br />"; } else { $query = "SELECT * FROM tbnlmembers WHERE user='$user'"; if (mysql_num_rows(queryMysql($query))) { $error = "That username already exists<br /><br />"; } else { $query = "INSERT INTO tbnlmembers VALUES(NULL, '$user', MD5('$pass'), '$fname', '$lname', '$email')"; queryMysql($query); } header('Location: http://mysite.com/users/tbnl-login.php'); die(""); } } echo <<< _END <div id="user-sign-up-form"> <form method='post' action='tbnl-signup.php'> $error $error1 $error2 <ul class="single"> <li><label>First Name</label><input type='text' maxlength='16' name='fname' value='$fname' /></li> <li><label>Last Name</label><input type='text' maxlength='16' name='lname' value='$lname' /></li> <li><label>Desired User Name</label><input type='text' maxlength='16' name='user' value='$user' onBlur='checkUser(this)'/><br /><label> </label><span id='info'></span></li> <li><label>Password</label><input type='password' maxlength='16' name='pass' value='$pass' /></li> <li><label>Re-Enter Password</label><input type='password' maxlength='16' name='repass' value='$repass' /></li> <li><label>Email</label><input type='text' maxlength='32' name='email' value='$email' /></li> <li><label>Re-Enter Email</label><input type='text' maxlength='32' name='reemail' value='$reemail' /></li> <li><input type='submit' value='Signup' /></li> </ul> </form> </div> _END; include ("../inc/page-bot.php"); ?> With the code in place, I was able to get it to not submit if i don't include @ in the email, but the email value always ended up being "1" no matter what email I type in. Any thought, greatly appreciated thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/172732-adding-email-verification-help/ Share on other sites More sharing options...
ignace Posted September 1, 2009 Share Posted September 1, 2009 $email = is_valid_email($_POST['email']) ? $_POST['email'] : null; PS eregi is deprecated consider using preg_match Quote Link to comment https://forums.phpfreaks.com/topic/172732-adding-email-verification-help/#findComment-910467 Share on other sites More sharing options...
blesseld Posted September 1, 2009 Author Share Posted September 1, 2009 That worked, Also changed to preg_match() came back Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in /home/tbaynigh/public_html/users/inc/tbnl-functions.php on line 55 added ^ befor the end " ^" is that why eregi() is depreciated? Also woulda never guessed $email = is_valid_email($_POST['email']) ? $_POST['email'] : null; what does the end ? $_POST['email'] : null; do? this is for my sake of understanding. Is it to repost the 'email' variable? Quote Link to comment https://forums.phpfreaks.com/topic/172732-adding-email-verification-help/#findComment-910473 Share on other sites More sharing options...
ignace Posted September 1, 2009 Share Posted September 1, 2009 what does the end ? $_POST['email'] : null; do? this is for my sake of understanding. Is it to repost the 'email' variable? Well you did: $email = is_valid_email($_POST['email']); Which stores the result of your function into $email thus 1 (true) or 0 (false). ? and : are called ternary operator's and their operation is the same as if you wrote an if and an else like: if (is_valid_email($_POST['email'])) { $email = $_POST['email']; } else { $email = null; } Where I would write (and is the same as the above if/else statement): $email = null; if (is_valid_email($_POST['email'])) { $email = $_POST['email']; } Quote Link to comment https://forums.phpfreaks.com/topic/172732-adding-email-verification-help/#findComment-910476 Share on other sites More sharing options...
blesseld Posted September 1, 2009 Author Share Posted September 1, 2009 Thankyou, I completely understand. Quote Link to comment https://forums.phpfreaks.com/topic/172732-adding-email-verification-help/#findComment-910480 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.