PDO: defining parameters using foreach and $_POST

前端 未结 1 1832
野的像风
野的像风 2021-01-24 01:01

I\'m trying to create a page that allows users change their info in a sql database using PDO. I\'m new to this and I\'m running into an error. I\'m using this as a source: http:

1条回答
  •  -上瘾入骨i
    2021-01-24 01:29

    I have simplified the code to illustrate how to create dynamic UPDATE query. This uses "lazy" binding and regular placeholders ?.

    The text inputs are set as a regular array (ie. not associative) of values.

    ";
            print_r($query_params);
            // Execute the query
            $stmt = $db->prepare($query);
            $result = $stmt->execute($query_params);
        }
    }
    ?>
    

    Typical result

    UPDATE `users` SET `info1` = ?,`info2` = ? WHERE `id` = ?
    Array ( [0] => john [1] => smith [2] => johnsmith ) 
    

    0 讨论(0)
提交回复
热议问题