Cannot insert nor update row in database


so I am using a separate database to store access codes for users.
The table looks like this:

Screenshot 2020-06-10 at 20.01.50

I am able to query and search for the codes like so:

$personalKeys = Db::query('SELECT * FROM personalkeys WHERE personalkey = "' . $enteredKey . '"');

Now I want to update the ‘taken’ column from the queried row like so:

$bool = Db::update('personalkeys', ['personalkey' => $enteredKey], ['taken' => '1']);

but it seem to do anything, although dump($bool) prints out ‘1’!
Inserting a new row doesn’t seem to work either.

Am I missing something?

I think the order of your arguments is wrong. You want to update the “taken” column, where personalKey = enteredKey, right?

$bool = Db::update('personalkeys', ['taken' => '1'], ['personalkey' => $enteredKey]);

Also, make sure that the taken column accepts a string and not an integer, or pass an integer as value.

1 Like

Thank you! That worked! Any reason that method cannot be found in the reference yet? The guide only gives an example making it not clear which value is the one to update and which one is the WHERE clause, although I might have figured that out by looking at the order of parameters above.

Because these are shortcuts that are not generated automatically, most methods are here: