How to loop through an update query in pdo? [duplicate]

  mysql, php

Could anyone please tell me what I am doing wrong in this code?

$dbname = "mysql:host=localhost;dbname=online_examination";
$username = "root";
$password = "";
$conn = new PDO ($dbname, $username, $password);

$questionId = $_POST['question_id'];
$optionTitle_1 = $_POST['option_title_1'];
$optionTitle_2 = $_POST['option_title_2'];
$optionTitle_3 = $_POST['option_title_3'];
$optionTitle_4 = $_POST['option_title_4'];

$optionTitle = array($optionTitle_1, $optionTitle_2, $optionTitle_3, $optionTitle_4);

foreach ($optionTitle as $option) 
    { 
        $sql = "UPDATE `option_table` SET option_title = :option_title WHERE question_id = {$questionId}";
        $stmt = $conn->prepare($sql);
        $stmt->bindParam(':option_title', $option);
        $stmt->execute($option);

    }

$conn = null;

Source: Ask PHP

LEAVE A COMMENT