c_pattle Posted May 13, 2010 Share Posted May 13, 2010 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/ Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 http://php.net/manual/en/function.unset.php Quote Link to comment https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/#findComment-1057768 Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/#findComment-1057770 Share on other sites More sharing options...
Muddy_Funster Posted May 13, 2010 Share Posted May 13, 2010 How can I clear the variables after the user clicks the submit button? Unset won't work... I just answerd his question, never said it would solve the problem. I find it is better to find these things out for yourself, that way it sticks better. Quote Link to comment https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/#findComment-1057774 Share on other sites More sharing options...
c_pattle Posted May 13, 2010 Author Share Posted May 13, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/#findComment-1057788 Share on other sites More sharing options...
c_pattle Posted May 13, 2010 Author Share Posted May 13, 2010 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 = Quote Link to comment https://forums.phpfreaks.com/topic/201640-still-trying-to-clear-variables/#findComment-1057790 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.