Dada78 Posted January 27, 2008 Share Posted January 27, 2008 On my registration form I use preg match so people can not just enter random text to register, they have to enter in a email format. For example if you just entered "This is my email" it will reject it and show and error. The only problem is it doesn't show any error. It will reject it and it works like it is suppose to but it doesn't show the user that it is an invalid email like it is suppose to. All the other errors on the page works and I get no errors that nothing is wrong. Everything works like it is suppose to with the exception the error "Invalid Email" doesn't show when it rejects a non email format. The code for the preg match is right above the query <?php // here, we check if the form has been submitted, because we need to handle // redirection before we handle outputting the HTML stuff. if (isset($_POST['submit'])) { if (empty($_POST['email'])) { $error = 'Please fill in email field.'; } if (empty($_POST['password'])) { $error = 'Please fill in desired password field.'; } } else { // MAKE CONNECTION include ('db_connect.php'); // connect to the mysql server $link = mysql_connect($host, $username, $password) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); $error = ""; $email = $_POST['email']; $pwd = $_POST['password']; // check if the email is taken (safe query): $query = sprintf("SELECT `email` FROM `users` WHERE `email` = '%s'", mysql_real_escape_string($_POST['email'])); $qry = mysql_query($query) or die ("Could not match data because ".mysql_error()); $num_rows = mysql_num_rows($qry); if ($num_rows < 1) { // Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON. if(get_magic_quotes_gpc()) { $product_name = stripslashes($_POST['email']); $product_description = stripslashes($_POST['password']); } else { $product_name = $_POST['email']; $product_description = $_POST['password']; } if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name)||!mail($product_name)) $error = "Invalid email"; else { // Make a safe query $query = sprintf("INSERT INTO users (`email`, `password`) VALUES ('%s', '%s')", mysql_real_escape_string($email, $link), mysql_real_escape_string($password, $link)); $result = mysql_query($query, $link); // If there is no result, or there was not at least 1 row affected, die... if(!$result || mysql_affected_rows() < 1) { $error = 'Could not insert user because ' . mysql_error(); } else { // redirect them to the user account page, because we successfully ran the SQL // notice how we haven't output ANYTHING to the browser yet- header() works header('Location: user.php'); exit(); } } } else { $error = 'That email is already in use, please select a different one.'; } } // If they've posted but there was an error, kindly show their email address for them again. if(isset($_POST['email'])) $email = $_POST['email']; else $email = ''; ?> -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/ Share on other sites More sharing options...
Dada78 Posted January 28, 2008 Author Share Posted January 28, 2008 This is the peice of code above I am talking about. Is this problem to hard? } if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name)||!mail($product_name)) $error = "Invalid email"; else { Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-450858 Share on other sites More sharing options...
teng84 Posted January 28, 2008 Share Posted January 28, 2008 try this code if(eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",$email)){ //valid mail if(mail(to,subject,message)){ echo 'mail sent'; }else{ echo 'mail not sent'; } } Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-450871 Share on other sites More sharing options...
Dada78 Posted January 28, 2008 Author Share Posted January 28, 2008 Thank you for your help but you didn't read my first post or I don't think you understand what I am trying to do. Look at my first post. Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-450875 Share on other sites More sharing options...
Dada78 Posted January 28, 2008 Author Share Posted January 28, 2008 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-451059 Share on other sites More sharing options...
rajivgonsalves Posted January 28, 2008 Share Posted January 28, 2008 this if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name)||!mail($product_name)) should be if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name) && !mail($product_name)) you should use && (and) instead of || (or) Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-451062 Share on other sites More sharing options...
Dada78 Posted January 28, 2008 Author Share Posted January 28, 2008 this if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name)||!mail($product_name)) should be if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name) && !mail($product_name)) you should use && (and) instead of || (or) That still doesn't work, it doesn't show any error if a user tries to register with a non email format. Their is was nothing wrong with the code I was using. It rejected non email formats, the problem I am having is ITS NOT POSTING AN ERROR when it rejects a non email. Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-451073 Share on other sites More sharing options...
Dada78 Posted January 28, 2008 Author Share Posted January 28, 2008 Ok I have got the error to show but now it won't go away as you can see here http://mesquitechristmas.com/local/register.php The code that produces this error is this. } if (!preg_match("/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i",$product_name)||!mail($product_name)) $error = "Invalid email"; else { It is suppose to show the error if you enter a non email format. For example "This is my email" instead of email@email.com It does work and reject no email formats but now the error will not go away. For the full code look at my first post. If anyone can help that would be great -Thanks Quote Link to comment https://forums.phpfreaks.com/topic/88019-invaild-email/#findComment-451104 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.