Jump to content

Can I stop the script from openin the action page if the user enters the wr...


Recommended Posts

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());
}
}



?>

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();
}

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

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

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.