Jump to content

[SOLVED] mysql update


ngreenwood6

Recommended Posts

I am trying to create a reset password section for my login script.  My database looks like this:

 

login=database

members=table

username, password, email, etc.=input values

 

I am trying to get it so that when a user submits the password change it updates the password (note:password is md5). I am using this command:

 

"UPDATE members SET password = '$new_pass' WHERE password = '$reset_email'"

 

$reset_email = $_POST['reset_email'] and $new_pass = $_POST['new_pass'] which are given from the form. However whenever i submit the form it changes the password, but I don't know what to. No password i type works and the md5 changes. Am i missing something? Any help is appreciated.

Link to comment
Share on other sites

What is the rest of your code? With setting $new_pass, $reset_email variables and stuff. If reset email is an --email-- why would you check for it in a --password-- column?

 

And as cooldude said it should be

WHERE userid = '$myuserid'

 

Otherwise it will update every password from "lol" to "lol2".

Link to comment
Share on other sites

sorry i typed it wrong my code is actually:

"UPDATE members SET password = '$new_pass' WHERE password = '$reset_email'"

 

The code is in 2 pages

 

reset_password.php:

<table>
			<form name="password_reset" method="post" action="reset.php">
			<tr>
			<td>Email
			<td>:
			<td><input name="reset_email" type="text" />
			</tr>
			<tr>
			<td><input name="submit" type="submit" value="submit" />
			</tr>
			</form>
			</table>

 

and reset.php:

<?php

$reset_email = Trim(stripslashes($_POST['reset_email']));

$host="localhost"; // Host name 

$username="root"; // Mysql username 

$password=""; // Mysql password 

$db_name="login"; // Database name 

$tbl_name="members"; // Table name 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 

mysql_select_db("$db_name")or die("cannot select DB");


$sql="SELECT * FROM members WHERE email = '$reset_email'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

if($count==1){
$row = mysql_fetch_array($result);
}
?>
<table>
<form name="reset" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<tr>
<td><?php echo $row['security']; ?>
<td>:
<td><input name="answer" type="text">
</tr>
<tr>
<td>New password
<td>:
<td><input name="new_pass" type="text">
</tr>
<tr>
<td><input name="submit" type="submit" value="submit">
</tr>
</form>
</table>
<?php

$new_pass = Trim(stripslashes(md5($_POST['new_pass'])));

//define the database variables
$host = "localhost";
$db_name = "login";
$db_table = "members";
$db_username = "root";
$db_password = "";

//function to insert the data into the database
$update_db = "UPDATE members SET password = '$new_pass' WHERE email = '$reset_email'";

//variable to connect to database
$mysqli_connect = mysqli_connect($host,$db_username,$db_password,$db_name)
or die ("Could not connect to database");

//variable to send data to the database
mysqli_query($mysqli_connect,$update_db)
or die ("Error: ".mysqli_error($mysqli_connect));

?>

 

I am trying to update the password after the user inputs their email address and verifies their security question. That is still in the works but the password update isnt working for now.

Link to comment
Share on other sites

i think this is getting bit confusing, if you want to reset or change password why not make the user to type his old password then type a new one.

 

so it will be like:

 

"UPDATE members SET password = '$new_pass' WHERE password = '$old_pass'"

 

after all you should make sure that you are changing the correct password from the correct user.

Link to comment
Share on other sites

I am a noob. i am trying to get it to update the passwrod for the email address that gets submitted the page before. Please help!

 

elflacodepr - I am getting them to put in their email address and then it goes to the next page. I want them to put in their email address, then confirm their security question, then enter their new password.

Link to comment
Share on other sites

i am sorry once again. stephen that is actually what my code was. I just figured out what the password it is setting is. It is setting a blank password when i submit.

 

lemoninflux - 2 users cant have the same email address it is prohibited.

 

Nothing stops them having the same password though?

 

----------------

Now playing: Linkin Park - No More Sorrow (Live At Milton Keynes)

via FoxyTunes

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.