I'd just add that you'd probably do better to separate your php and html as much as possible. Mixing them up can make pages hard to maintain, even if it looks more logical to do so. ... This means that you can place your code into a function, a class, an include file, whatever. No big deal though.
There are a couple of errors in your code ( to execute you need to prepare first and your execute should be $stmt->execute(), not $stmt = $pdo->execute()) I actually find using foreach with PDO tends to work better for some reason. I would also agree with diafol that you should separate your PHP and HTML but I would go even further than he has ... This is not tested