I want to update the password in the database. And I can’t have tried everything. I do not understand what is wrong (here is the form of changing the password

<input type="password" placeholder="Old password" name="lastpass" value=""> <input type="password" placeholder="New password" name="newpass" value="" > <input type="password" placeholder="Repeat new password" name="newpassw" value="" > <input type="submit" class="btn_savechange" value="Save" name="savech" /> 

Here's a password change code that doesn't work.

 <?php if(isset($_POST['savech'])) { $lastpass = $_POST['lastpass']; $newpass = $_POST['newpass']; $newpassw = $_POST['newpassw']; if ($newpassw == $newpass) { $qery = mysql_query("SELECT * FROM users WHERE login = 'login'") or die(mysql_error()); if (mysql_num_rows($qery) == 1) { $updated = "UPDATE users SET password = '$newpass' WHERE login = 'login'"; if(mysql_num_rows($update) > 0) { echo "Good"; } else { echo "mistake"; } } else { echo "Oshibka"; } } } ?> 

The user is authorized and the data is recorded in sessions. Maybe through them you need to pull it out. Help code fix.

  • @ Amir90, To format a code, select it with the mouse and click on the {} button of the editor. - ReinRaus
  • yes no they are the same $ update, $ updated. I copied it, so I fixed it), but did you die of the function and what should I use ??? - Amir90
  • died and use now (for a long time) you need PDO - why, how and why explain here: Why you should use PDO to work with the database - zippp
  • I hope this is a test code? You can save passwords only in a hashed form. - Andrew Frolov

2 answers 2

Everyone tried it for sure? :) And look at the code?

 $updated = "UPDATE users SET password = '$newpass' WHERE login = 'login'"; if(mysql_num_rows($update) 

Variable names are different - $ update, $ updated

mysql_ functions have already died, they are not used.

I think soon there will be more of a hashcode, such questions will be blocked.

    For update, you need to call mysql_query , not mysql_num_rows .

    • o) thanks earned))))))))))))))) - Amir90