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
https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/
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 = [email protected]

 

; 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 =

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.