PDO/PHP Script Query Database (Game Server baning system) -
the database structure:
- name: person offense against
- reason: reason given punishment
- admin: issued punishment
- id: pk
- type: 1,2,3,4,5
type 3 : kick type 0: ban
the way it's setup once player given punishment add new row database. i'm trying create php script players can enter usernames on website (their username=name field in database , show offenses on account.
what have far:
$name = $_get["username"]; try { $conn = new pdo('mysql:host=localhost;dbname=server', 'username', 'pass'); $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception); $data = $conn->query('select * logs name = ' . $conn->quote($name)); } catch(pdoexception $e) { echo 'error: ' . $e->getmessage(); }
i'm not sure go here in terms of displaying data if above correct or not.
straight pdo tag wiki
$stmt = $conn->prepare('select * logs name = ?'); $stmt->execute(array($_get["username"])); $data = $stmt->fetchall(); ?> <table> <? foreach ($data $row): ?> <tr> <td><?=$row['type']?></td> <td><?=$row['admin']?></td> <td><?=$row['reason']?></td> </tr> <? endforeach ?>