Jump to content

Change email php script is not working


ethan89

Recommended Posts

This is completely different code than my change password script thread.  This is not double posting.

 

Whenever I use this script to change my email, it just changes the email to nothing (blank).  What could be wrong with it?  Help is hugely appreciated.  I know you don't have to use your valuable time to help me.

 

<?php

 

// I removed the connect to db part

 

session_start();

 

$username = $_SESSION['username'];

$email = $_POST['email'];

$newemail = $_POST['newemail'];

$confirmnewemail = $_POST['confirmnewemail'];

 

$result = mysql_query("SELECT email FROM members WHERE username='$username'");

if($email!= mysql_result($result, 0))

{

echo "The email address you entered is incorrect.";

}

if($newemail==$confirmnewemail)

    $sql=mysql_query("UPDATE members SET email='$newemail' where username='$username'");

    if($sql)

    {

    echo "You have successfully changed your email address.";

    }

else

{

echo "The new email and confirm new email fields were different.";

}

?>

Link to comment
Share on other sites

Sure, thanks for helping me out.

 

<?php

session_start();

if(!isset($_SESSION['username']) ||

(trim($_SESSION['username'])=='')) {

header("location: members_only_area.php");

exit();

}

?>

 

<form action="change_password22.php">

password<input type="password" name="password">

new password<input type="password" name="newpassword">

confirm new password<input type="password" name="confirmnewpassword">

<input type="submit" value="Change Password">

</form>

Link to comment
Share on other sites

Sure, I can do that, but I just realized that I gave you the wrong code.  That's the second time today.  I don't know what is wrong with me.  Here it is:

 

<form action="change_email.php">

Current Email: <input type="text" name="email">

New Email: <input type="text" name="newemail">

Confirm New Email: <input type="text" name="confirmnewemail">

<input type="submit" value="Change Email">

</form>

Link to comment
Share on other sites

When you submit the form, I'm sure you 'll notice the address in the browser suddenly has a string behind the URL something like

/change_password.php?password=something&newpassword=something_else.

That's because if you don't specify a method= in your form tag, the method defaults to GET whereas in the script, you're looking for POST variables coming in. All you should need to do to fix it is change the <form tag to

<form action="change_password22.php" method="post">

Link to comment
Share on other sites

Ohhhhhhhhhhhhhhhhhhh I was really concerned about the password being displayed at the top lol.  Thanks for searching through my garbage code and finding my silly mistake!  I really don't think I could ever spot that on my own  :D.  Thanks so much for helping me!  I'll post again to tell you if it changes the password or not :)

Link to comment
Share on other sites

Well, it's a big improvement that it doesn't show the info in the URL anymore, but instead of changing the password or making the password blank, now it just doesn't do anything and the password stays the same..  Maybe I can solve this on my own now that it's not hugely messed up anymore, but it would be cool if someone could tell me what's wrong  ;).  I will mark this as solved as soon as it's fixed.

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.