MrGuitarWizard
MrGuitarWizard

Reputation: 1

PDO Query not updating

I have set up my query correctly it comes back with NO errors at all but for someone reason does not update

$database->updateAdmin(1, $_POST['user']);

 public function updateAdmin($status, $uid) {
    $sql = 'UPDATE users SET admin = :status WHERE uid = :uid';
    $result = $this->pdo->prepare($sql);
    $result->execute([
        ':status' => $status,
        ':uid' => $uid
    ]);
}

<select name="user">
      <option value="1">John</option>
     <option value="2">Sarah</option>
 </select>

admin field is ENUM ('0','1')

This is how it is all set up it just says it went ok but never updates, can anyone spot maybe why?

Upvotes: 0

Views: 80

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 158005

To make it come with errors you have to ask for them.
Have you set your PDO in exception mode?

However, there could be a hard-spotted trick.
You have to bind your 1 as a string, not as a number. Otherwise it won't update.
I am not quite familiar with automatic binding from array, but it is quite possible that PDO does some magic and binds your 1 as a number. So, I'd bind it manually, to be sure.

Upvotes: 1

Related Questions