Hey guys, I am creating a form that allows a logged in user to enter a new password for their, account, I already have the query set up to update the password, but in my form I have the first input set to take the existing password, which must match the existing value of password in the database before the update will be performed. I cannot figure out how to do this check, the whole thing must be done with one POST submit. Check the entered password matches the one currently in the database and if it matches then updates the current value to that of the passwordnew value. here is my form:

sqlsrv_rows_affected will tell you how many rows were affected by the previous UPDATE query. If the person gave a bad 'current password', then the WHERE clause would cause the update query to update 0 rows. If they gave a correct current password, then the UPDATE query would have affected 1 row.

deucalion0
—
2012-02-23T18:48:24Z —
#5

I think I am almost there I always get password incorrect whether the row was updated or not, any suggestions why?

Is the row updating? Have you verified that? Try making it === 0 instead of ==... (Might be returning FALSE)

deucalion0
—
2012-02-23T19:04:37Z —
#7

The row is definitely updating, I changed it to === now I am just getting a blank screen whether the password is correct or not, but when I enter the correct password it will change the password to the desired new password. I have no idea why the output isn't working

StarLion
—
2012-02-23T19:10:04Z —
#8

sqlsrv for some reason is returning FALSE, despite actually completing the transaction. (you can verify this by doing var_dump(sqlsrv_rows_affected($stmt)); It should come up as bool(false))

deucalion0
—
2012-02-23T19:14:55Z —
#9

Yes you are right it is indeed returning bool(false)

I have no idea why because I know the password is changing I am checking it every time.

StarLion
—
2012-02-23T19:18:55Z —
#10

Yes, that's very strange....I'm going to tag a few people here....@Cups@r937@guido2004 : Guys, any idea why this function might be throwing FALSE while still executing?

deucalion0
—
2012-02-23T19:39:57Z —
#11

I really appreciate your help with this!!

Cheers!

guido2004
—
2012-02-23T21:26:00Z —
#12

I never used the sqlsrv extension, but after reading the manual I'd advise you to try what you can see in example #1

Hi Guido2004, my code originally came from the exact source you suggested. I have tried the exact same code as the manual and it still returns false, even when the password is being updated. Thanks for your input.

guido2004
—
2012-02-23T21:45:53Z —
#14

Did you add the if-elseif-else? It should give you an error message if rows_affected is false.

deucalion0
—
2012-02-23T22:35:20Z —
#15

I did add everything, and nothing changed, but now I deleted the last half of my statement now it is doing something else, it seems to be working, if I could just figure out how to convert it into "The password was changed" or "Incorrect password, try again"