PHP / PDO echo data from database into a table

Ok so I have figured it out <?php $getUser = $db->prepare(“SELECT * FROM users”); $getUser->execute(); $users = $getUsers->fetchAll(); <table> <tr> <th>Username</th> <th>Password</th> </tr> <?php foreach ($users as $user) { ?> <tr> <td><?php echo $users[‘username’] ?></td> <td><?php echo $users[‘password’] ?></td> </tr> <?php } ?> </table> It now echo’s every username and password inside the table. even … Read more

PDO Fetch statement only retrieves first column

You can only select the id column because that is all you have in the query. Try something like this if (isset($_SESSION[‘id’])) { $presh = $_SESSION[‘id’]; $stmt = $pdo->prepare(“SELECT id, karmacurrent FROM users WHERE id = :id”); $id = $presh; $stmt->execute( array( ‘:id’=>$id ) ); $accountinfo = $stmt->fetch(PDO::FETCH_ASSOC); } Basically you were only retrieving the … Read more

PHP PDO and Mysql [closed]

Here’s a rough answer which should resolve the injection issue, the non-executing query issue, and the incorrect insert syntax. I don’t have your DB so I can’t confirm this is fully functional but it should be closer.. <?php // include to get database connection include_once ‘config/db.php’; try{ $a_id = “SELECT a.id as aid FROM aluno … Read more