Got an error while deleting the account.

tl0tr
9 years ago

0

I got an error message while deleting the account which I just temporary created to check if one of the level works.

Below is the error message.

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (hackthis.users_medals, CONSTRAINT users_medals_ibfk_1 FOREIGN KEY (user_id) REFERENCES users (user_id))

8replies
5voices
246views
Mr. Cyph3r [MrCyph3r]
9 years ago | edited 9 years ago

0

Yeah, I noticed that some days ago… I was thinking to fork the repo in order to fix it, but unfortunately I haven’t got the time yet :(

I suppose it is something related to the current session, it should be easily fixed with a cleanup of the current user session (like on logout).

dloser
9 years ago

1

Could very well be. Don’t see any problems with the delete itself and the error is talking about ‘add or update’. The session isn’t invalidated and also not verified on loading a page. Looking at the code, it is probably trying to add a veteran medal, because null < strtotime(‘-1 year’).

@flabbyrabbit!!! shakes fist

Mr. Cyph3r [MrCyph3r]
9 years ago

0

Hmm I see…
There is also a quick fix, by editing account.php at this location:

``` else if (isset($GET[ ‘delete’])) {
$status = $app->user->delete($
POST[ ‘delete’], $_POST[ ‘token’]);

if ($status === true) {
header(‘Location: /?deleted’);
die();
}```

Before redirecting to ?deleted you can destroy the session as in logout.php

There might be a better way, what do you think?

Mr. Cyph3r [MrCyph3r]
9 years ago

0

Oops sorry, formatting of the code is ugly… it must be because I’m posting from my phone :s

dloser
9 years ago

0

Downside is that ?deleted is exactly the place where it tries to add the medal before even getting to the ?deleted part. It’s perhaps nicer to split the logout function in the user class so you have an invalidate_session function and use that function either in the delete function itself or after the call to it.

Luke [flabbyrabbit]
9 years ago

0

It turns out:

$this->logout();

Is fairly important. I’ve added it to the script things are happily destroyed now. @dloser was right that the problem was with the medal being added rather than being deleted, as you were still logged in but with no user details the medal script got confused and tried to award you medals for no reason.

Mr. Cyph3r [MrCyph3r]
9 years ago

0

Yup, now I see… I missed this piece of the puzzle :)

Mugi [Mugiwara27]
9 years ago

0

Got the same error, just delete cookies and it’ll work

You must be logged in to reply to this discussion. Login
1 of 9

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss