Jump to content

still trying to clear variables


c_pattle

Recommended Posts

I have a page that registers a new user to a database.  However when you refresh the page the variables that are used to add information to the database still contain information so it keeps trying to add the user to the database.  How can I clear the variables after the user clicks the submit button?

 

<?php
//Adding a new user into the database

//trying to clear variables
header('Location: register.php'); 

$register_firstname = $_POST['register_firstname'];
$register_lastname = $_POST['register_lastname'];
$register_username = $_POST['register_username'];
$register_email = $_POST['register_email'];
$register_password_1 = $_POST['register_password_1'];
$register_password_2 = $_POST['register_password_2'];

if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) { 
if( $register_password_1 == $register_password_2) {
$sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";

$rs = mysql_query( $sql, $link );
if($rs) {
echo("congratulations you have successfully registered");
} else {
echo ('error' . mysql_error());
}

}

else {
	echo ("The two passwords do not match.  Please retype them");
}
}

else {
echo ("You have not completed all the fields.  Please fill in the blank fields");
}
?>

Link to comment
Share on other sites

Unset won't work. The "problem" is that the OP is processing form data. If the user hit's refresh, the old data is sent to the form. The solution is to check if the user has registered before trying to register again.

 

Ken

Link to comment
Share on other sites

The forms check to see if the user has registered already once its sent.  I have other forms on this website that have the same problem with not clear variables.  You said there was a way to do this using meta tags?  Would that be easier?

Link to comment
Share on other sites

also I've updated the code to try to send an email to the user once they register but that doesn't seem to be working. 

 

<?php
//Adding a new user into the database

//trying to clear variables
header('Location: register.php'); 

$register_firstname = $_POST['register_firstname'];
$register_lastname = $_POST['register_lastname'];
$register_username = $_POST['register_username'];
$register_email = $_POST['register_email'];
$register_password_1 = $_POST['register_password_1'];
$register_password_2 = $_POST['register_password_2'];

if( $register_firstname and $register_lastname and $register_username and $register_email and $register_password_1 and $register_password_2) { 
if( $register_password_1 == $register_password_2) {
$sql="insert into users (first_name, last_name, username, email, password) values (\"$register_firstname\", \"$register_lastname\", \"$register_username\", \"$register_email\", \"$register_password_1\")";

$rs = mysql_query( $sql, $link );
if($rs) {
echo("congratulations you have successfully registered");
$to = $register_email;
$re = "registration to Ribbons2Roses";
$msg = "Congratulations". $register_firstname . "you have successfully register to Ribbons2Roses.  Your username is" . $register_username . "We hope you enjoy shopping for that perfect gift on our website and if you have any questions please don't hestitate to contact one of the team";
mail( $to, $re, $msg );
} else {
echo ('error' . mysql_error());
}

}

else {
	echo ("The two passwords do not match.  Please retype them");
}
}

else {
echo ("You have not completed all the fields.  Please fill in the blank fields");
}
?>

 

Here is the related text in the php.ini file

 

[mail function]

; For Win32 only.

SMTP = localhost

smtp_port = 25

 

; For Win32 only.

;sendmail_from = me@example.com

 

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").

sendmail_path = sendmail -t -i

 

; Force the addition of the specified parameters to be passed as extra parameters

; to the sendmail binary. These parameters will always replace the value of

; the 5th parameter to mail(), even in safe mode.

;mail.force_extra_parameters =

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.