php - PDO Query not updating

630

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?

273

Answer

Solution:

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.

People are also looking for solutions to the problem: PHP file download including the .php file when only pdf is wanted

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.