Modernvox Posted January 26, 2010 Share Posted January 26, 2010 wrong info? If the user does not fill in all required fields or enters an invalid email format I want to avoid opening my registration success page because it is all filled out to prompt on a successful registration. wrong info? If the user does not fill in all required fields or enters an invalid email format I want to avoid opening my registration success page because it is all filled out to prompt on a successful registration. [code]<?php if ((isset($_POST['submit'])) && (!empty($_POST['regname'])) && (!empty($_POST['regstate'])) && (!empty($_POST['regcity'])) && (!empty($_POST['regemail'])) && (!empty($_POST['username'])) && (!empty($_POST['password'])) && (!empty($_POST['confirmpass']))) { $pattern = '/^[a-z0-9]{4,}+.?([a-z0-9]+)?@([a-z0-9]+\.)+[a-z]{3,4}$/i'; if (preg_match($pattern, $reg_email)) { $reg_name= $_POST['regname']; $reg_state= $_POST['regstate']; $reg_city= $_POST['regcity']; $reg_email= $_POST['regemail']; $reg_username= $_POST['username']; $reg_password= $_POST['password']; $reg_confirmpass= $_POST['confirmpass']; $database= register; $dbx =mysql_connect("localhost", "root", ""); if (!$dbx) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db($database); if (!$db_selected) { die ("Could not select the database: <br />" . mysql_error()); } $insert_query = "INSERT INTO users (regname, regstate, regcity, regemail, username, password ) VALUES ('$reg_name','$reg_state','$reg_city','$reg_email','$reg_username', '$reg_password')"; } else echo "I wanna stop the reg_success page from opening"; //What to do? $result= mysql_query($insert_query); if (!$result){ die ("Could not query the database: <br />". mysql_error()); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/189804-can-i-stop-the-script-from-openin-the-action-page-if-the-user-enters-the-wr/ Share on other sites More sharing options...
mikesta707 Posted January 26, 2010 Share Posted January 26, 2010 you can use the following regex pattern to validate emails $pattern = "#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$#"; note i use # as a delimiter. an example $email = "bad email"; if (preg_match($pattern, $email)){ echo "good email"; else { echo "bad email"; } output: bad email sorry forgot other part. if you want to test for empty fields, use the empty() function, IE if (empty($field)){ echo "field is empty. Fail!"; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/189804-can-i-stop-the-script-from-openin-the-action-page-if-the-user-enters-the-wr/#findComment-1001624 Share on other sites More sharing options...
Modernvox Posted January 26, 2010 Author Share Posted January 26, 2010 you can use the following regex pattern to validate emails $pattern = "#^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$#"; note i use # as a delimiter. an example $email = "bad email"; if (preg_match($pattern, $email)){ echo "good email"; else { echo "bad email"; } output: bad email sorry forgot other part. if you want to test for empty fields, use the empty() function, IE if (empty($field)){ echo "field is empty. Fail!"; exit(); } Hi Mike, That part of the code is actually working fine, my question is How do I kill the script from opening the reg_success page if the user doesn't enter all required info or do i need to process the register page on it;s on page then open the reg_success page? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/189804-can-i-stop-the-script-from-openin-the-action-page-if-the-user-enters-the-wr/#findComment-1001627 Share on other sites More sharing options...
teamatomic Posted January 26, 2010 Share Posted January 26, 2010 if (isset($_POST['submit'])) { //check for data if ($_POST['username'] == '') {$username_error= 'fill in you user name';} else {$username=$_POST['username']; $error=1; //clean form input data here } // do an if/else for each form widget } if (!isset($_POST['submit'] || $error==1) { //do your form echo $username_error;// only shows if it has value...so wont show on the !isset echo "<input name=username value=\"$username\">";//note the var in user name-this repopulates the widget if there is an error but the names WAS filled out and the error is elsewhere // do this for all errors and widgets} } else { //do your registration stuff // then thank the registrant or whoever and what ever they did } HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/189804-can-i-stop-the-script-from-openin-the-action-page-if-the-user-enters-the-wr/#findComment-1001636 Share on other sites More sharing options...
Modernvox Posted January 26, 2010 Author Share Posted January 26, 2010 if (isset($_POST['submit'])) { //check for data if ($_POST['username'] == '') {$username_error= 'fill in you user name';} else {$username=$_POST['username']; $error=1; //clean form input data here } // do an if/else for each form widget } if (!isset($_POST['submit'] || $error==1) { //do your form echo $username_error;// only shows if it has value...so wont show on the !isset echo "<input name=username value=\"$username\">";//note the var in user name-this repopulates the widget if there is an error but the names WAS filled out and the error is elsewhere // do this for all errors and widgets} } else { //do your registration stuff // then thank the registrant or whoever and what ever they did } HTH Teamatomic Thanks , but I don't understand anything you have just posted, sorry. All I want to to do is show a registration page after successful registration that's all.. If any fields are left blank or the email format was entered correctly I don't want the user to see the reg_success page. Quote Link to comment https://forums.phpfreaks.com/topic/189804-can-i-stop-the-script-from-openin-the-action-page-if-the-user-enters-the-wr/#findComment-1001638 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.