Jump to content

Can someone tell me how to get my registration page to start out fresh.


cluce

Recommended Posts

Can someone tell me how to get my registration page to start out fresh.  For example, let say a user tries to register but the password fields are not identical. That person would recieve a message saying passwords are not identical.  So that person tries again and types in identical passwords but the username already exists. Even though the passwords match, that person will still recieve two messages one from before,"the password is not identical" and "the username is already in use".???  Its like my registration page isn't refreshed. It shows old error messages.

 

 

here is my code

<?php
session_start();
Header("Cache-control: private, no-cache");
Header("Expires: Mon, 26 Jun 1997 05:00:00 GMT");
Header("Pragma: no-cache");

//checks for identical passwords
if($_POST["password"]!==$_POST["confirmpassword"]){
        $_SESSION['identical'] = "Passwords are not identical.";
	header("Location: registration.php");
}  else {
$mysqli = mysqli_connect("localhost", "root", "", "test");
}
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}

$usercheck = $_POST['username'];
$check = mysqli_query($mysqli,"SELECT username FROM auth_users WHERE username = '$usercheck'"); 
$check2 = mysqli_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
$_SESSION['userExists'] = "<font color='red'>" .$_POST['username']. " is already in use. Please choose another username.</font>";	
    header ("Location: registration.php");

}  else  {

$sql = "INSERT INTO auth_users (username, password, ConfirmPassword, f_name, L_name, address, city, state, zip, phoneNumber, AltphoneNumber, email, company) VALUES ('".$_POST['username']."',PASSWORD('".$_POST["password"]."'),PASSWORD('".$_POST["confirmpassword"]."'),'".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['address']."','".$_POST['city']."','".$_POST['state']."','".$_POST['zip']."','".$_POST['phone']."','".$_POST['alternate']."','".$_POST['email']."','".$_POST['company']."')";
$res = mysqli_query($mysqli, $sql);

}
if ($res === TRUE) {
	header("Location: registered.html");
	} else {
printf("Could not insert record: %s\n", mysqli_error($mysqli));
}
mysqli_close($mysqli);

?>

Link to comment
Share on other sites

<?php
	if (!empty($_POST['submit'])) {
$regexemail = 
"^[A-Za-z0-9\._-]+@([A-Za-z0-9][A-Za-z0-9-]{1,62})(\.[A-Za-z][A-Za-z0-9-]{1,62})+$";
	$errorhandler .= "";
	if ($_POST['yourname'] == "") {
	$errorhandler .= "You left the name field blank<br />";
	}
	if ($_POST['emailaddress'] == "") {
	$errorhandler .= "You left the email address blank<br />";
	}
	if ($_POST['emailaddress'] != $_POST['verifyemail']) {
	$errorhandler .= "The email addresses do not match.<br />";
	}
	if (!ereg("$regexemail", $_POST['emailaddress'])) { 
	$errorhandler .= "The email address is improperly formatted<br />";
	}
	if(!(getmxrr(substr(strstr($_POST['emailaddress'], '@'), 1), $temp)) || checkdnsrr(gethostbyname(substr(strstr($_POST['emailaddress'], '@'), 1)), "ANY")) {
	$errorhandler .= "The Domain name for the email address does not exist<br />";
	}	
	if ($_POST['regarding'] == "") {
	$errorhandler .= "The Category field was left blank<br />";
	}
	if ($_POST['specialinformation'] == "") {
	$errorhandler .= "The Special Information field was left blank<br />";
	}
	if ($_POST['description'] == "") {
	$errorhandler .= "The Description field was left blank<br />";
	}
	if ($errorhandler != "") {
	echo "<span style=\"color:red;\">";
	echo "$errorhandler";
	echo "</span>";
	}else {
	$visible = "false";
	$message = "
	Name: {$_POST[yourname]}
	Email Address: {$_POST[emailaddress]}
	Contact Phone: {$_POST[contactphone]}
	Category: {$_POST[regarding]}
	Special Information: {$_POST[specialinformation]};
	Description: {$_POST[description]}
	";
mail("businessman332211@gmail.com", "Freelance Businessman Contact Form", $message);
echo "Thank you for Contacting me.  I will respond within 1-24 hours at the latest.";
}		
}
	?>
	<?php
	if (empty($visible)) {
	?>
	<form name="contact" id="contact" action="contactme.php" method="post">
	<dl>
	<dt><label for="yourname">*First Name:</label></dt>
	<dd><input name="yourname" id="yourname" type="text" maxlength="80" 
	size="30" value="<?php echo $_POST['yourname']; ?>" /></dd>
	<dt><label for="emailaddress">*Email Address:</label></dt>
	<dd><input name="emailaddress" id="emailaddress" type="text" maxlength="80" 
	size="30" value="<?php echo $_POST['emailaddress']; ?>" />
	</dd>
	<dt><label for="verifyemail">*Verify Email:</label></dt>
	<dd><input name="verifyemail" id="verifyemail" type="text" maxlength="80"
	size="30" value="<?php echo $_POST['verifyemail']; ?>" /></dd>
	<dt><label for="contactphone">Phone:</label></dt>
	<dd><input name="contactphone" id="contactphone" type="text" maxlength="80" 
	value="<?php echo $_POST['contactphone']; ?>" />
	</dd>
	<dt><label for="regarding">*What is this related Too!</label></dt>
	<dd><input name="regarding" id="regarding" type="text" maxlength="80" 
	size="30" value="<?php echo $_POST['regarding']; ?>"/></dd>
	<dt><label for="specialinformation">*Purpose for contact</label></dt>
	<dd><input name="specialinformation" id="specialinformation" type="text" 
	maxlength="120" size="30" value="<?php echo $_POST['specialinformation']; ?>"
	/></dd>
	<dt><label for="description">*Message</label></dt>
	<dd><textarea name="description" id="description" cols="30" rows="20"></textarea>
</dd>
	<dt> </dt>
	<dd>
	<input name="submit" id="submit" type="submit" value="Send Message!" />
	<input name="reset" id="reset" type="reset" value="Clear Data!" />
	</dd>
	</dl>
	</form>
	<?php
	}
	?>

I don't really understand what you are asking, but if you are wanting to be able to record many different errors I use an "error handler".  you could also use it as an array or anything else.

There are hundreds of way's, this is just one quick example off of something quick, just so you can see one possibility.

Link to comment
Share on other sites

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.