Mysql field not updating

It’s the same. echo returns $Username to the ajax function. And that is the console.log of the data returned to ajax.

No, its not the same.
I want to see what query your script sent to the database.

Echo $sql.

Smart. I didn’t try that. Give me a sec…

If you don’t prevent it, the form data can be submitted by the browser too.

At this point I don’t know if what you are using to translate our replies into your native language is not working or you somehow think that posting small snippets of the problem tells us everything your code is or can do, but so far, this has just been a waste of time.

Just post all the complete code needed to reproduce this, less any database connection credentials - all the rest of the code besides the javascript and php that you have already posted.

The username and email fields, as already mentioned, must be defined as unique indexes, so that the database design enforces uniqueness. When you originally insert the row of data or for any update, your exception error handling for the query, which you don’t have, would test if the error number is for a duplicate index error, query to find which column(s) contain duplicate values, and setup message(s) for the user letting them know what was wrong with the data that they submitted. For all other error numbers and all other query types, just let php catch and handle and database exceptions.

Here is the mystery:

Untitled-1

The query and content of the variable are ok but no update is made for the fields Username and Email.

where id = ''? Doesnt look OK to me…

But it works fine for the rest of the fields. So?

no no wait a minute… let me check

That… that query will do exactly nothing.

I dont know why you would see any change in the database from that query. id cannot be the empty string. It cant be ANY string, because it’s an INT.

1 Like

Ok Thank for the help. I didn’t find the problem but thanks to you I found out how it happens. Somehow when I change the contenu of the input field my userID vanishes. Shouldn’t be too hard now to find why.

Thanks a lot!!! :+1:

Funny thing it just vanishes with the fields Username and Email. I will find it now. :grinning:

Best of luck to you. You’ll probably be redoing that section when you get to the ‘need to secure it’ bit, because right now, your script will let any person change any user’s password and email…

(I can send data to your form handler without using your form. So if i send a POST request with “Username” = “admin” and “Pwd” = “hahaihackedyou”… your script will happily change admin’s password.)

1 Like

I know; it’s ‘under construction’ just doing quick test to see if the general idea functions and after I will do the niceties. :slightly_smiling_face:

One note for going forward: a SQL database will not do “partial” updates of a row. If you tell it “update these values”, it updates all or none of them.

If you think something has updated some fields but not others, go back and check what was sent to the database; either you’re mis-remembering what was in the database and nothing was updated, or everything was updated, just not with the values you expected.

1 Like

I had never updated all fields at once. It’s for that I couln’t put my finger omn it. When I was updating only Pwd for exemple all went well. When I was trying to update Username ot Email I didn’t get any change. That’ s why I assumed that only those two fields of the table were not updated when in fact modifying Pwd only didn’t clear the User_ID only change of Username and Email did. That’s what was driving nut since this morning 5am!!! :slightly_smiling_face:

Now I take a deserved break and then I will have a look at those damned input fields.

Thanks again you put me on the right track :+1:

2 Likes

This logic is incorrect -

If you have submitted a different value for the username, the new value you entered doesn’t match the original row of data in the database, i.e. there’s no id to get or if you happen to choose someone else’s username, you would get their id.

Therefore, do this -

3 Likes

Yep Bingo that was the problem; took me time to see it… Sometime it so big it hits you right in the face and you can’t see it. :smirk:

Thank you for help; I appreciate it. :+1:

Plus it was doubly stupid since I had already the User_ID and I could have used that in my query instead of the Username and querying after the User_ID. :crazy_face: Well it was one of those days…

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.