RyanSF07 Posted June 30, 2009 Share Posted June 30, 2009 Hi Guys, I'm trying add "change your username and email address" functionality to my site. The Username is a Session Variable that is set when the user logs in. Users log in with their email address and password. I think when the update their username, the session should be destroyed and they should log back in, right? Can you help proof what I have below? Should I add if ($_SESSION[user_id]) { and delete a couple brackets? With the code below I'm getting these errors: Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in ... and Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent Thank you very much for your help! Here's what I have: <?php include_once ("contentdb.php"); // database connection include_once ("nav_home_login.inc"); if ($_POST[submit]) { // validation if ($_POST[email] <> "") { $a = TRUE; } else { $a = FALSE; $content .= "<p>Please enter your email address.</p>\n"; } if ($_POST[user_name] <> "") { $b = TRUE; } else { $b = FALSE; $content .= "<p>Please enter your username.</p>\n"; } // check to see if the user_name is in use $usercheck = $_POST[user_name]; $check = mysql_query("SELECT * FROM registered_users WHERE user_name = '$usercheck'")or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists give an error if ($check2 != 0) { $c = FALSE; $content .= "<p>Sorry, that username is already in use.</p>\n"; } else { $c = TRUE; } if ($a AND $b AND $c) { $query = "UPDATE registered_users SET registered_users.user_name = '$_POST[user_name]', registered_users.email ='$_POST[email]' WHERE registered_users.id = '" . $_SESSION['user_id'] . "'"; if (mysql_query($query)) { $recep = "$_POST[email]"; $subject = "Changes to Account Details"; $text = "Dear $_POST[user_name], Your account details have been updated: email: $_POST[email] username: $_POST[user_name] Best Regards, Ryan "; $headers2 = "MIME-Version: 1.0\r\n"; $headers2 .= "Content-type: text/plain; charset=UTF-8\r\n"; $headers2 .= "Reply-to: ryandetwiler@eslvideo.com\n"; $headers2 .= "X-Mailer: PHP\n"; mail($recep2,$subject2,$text2,$headers2); //destroy the session $_SESSION = array(); session_destroy(); $content .= "<h2>Your Account details have been successfully updated. Please log back in with your email address and password. <br><br><p> <form action = 'login_process.php' method = 'POST'> <b>Email:</b> <input type = 'text' name = 'email' size = '20' maxlength = '30'> <b>Password:</b> <input type = 'password' name = 'password' size = '10' maxlength = '15'> <input type = 'submit' name = 'submit' value = 'Login'> </form> </p> <br> "; } else { $content .= "<p>your changes could not be completed at this time.<br></p>"; } } else { $content .= '<p>Please click your browser\'s [back] button to return to the form.<br></p>'; } } include_once ("template_my_account_edit_details_pro.inc"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/164316-solved-how-do-you-make-an-update-then-destroy-the-session/ Share on other sites More sharing options...
RussellReal Posted June 30, 2009 Share Posted June 30, 2009 ok.. when you try to destroy the session.. you havn't started the session.. so you get an error. and then THAT error, sends your headers.. so session_start() can't actually start correctly Quote Link to comment https://forums.phpfreaks.com/topic/164316-solved-how-do-you-make-an-update-then-destroy-the-session/#findComment-866778 Share on other sites More sharing options...
RyanSF07 Posted June 30, 2009 Author Share Posted June 30, 2009 Thank you Russel, That and moving the session_destroy(); } to a different spot in the script seems to have done it. Cheers! Ryan Quote Link to comment https://forums.phpfreaks.com/topic/164316-solved-how-do-you-make-an-update-then-destroy-the-session/#findComment-866783 Share on other sites More sharing options...
RussellReal Posted June 30, 2009 Share Posted June 30, 2009 Anytime bro Quote Link to comment https://forums.phpfreaks.com/topic/164316-solved-how-do-you-make-an-update-then-destroy-the-session/#findComment-866786 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.